The Contact Admin page can be made better with search fields and filters. Also for the department field, it can be given as a autocomplete_field
for efficient assigning.
Make the following changes in the event/admin.py
:
@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
list_display = ('name', 'number', 'designation', 'department')
search_fields = ['name', 'number', 'designation',]
list_filter = ['department', 'designation']
autocomplete_fields = ['department']
def get_queryset(self, request):
qs = super().get_queryset(request)
if not request.user.is_superuser:
qs=qs.filter(workshop__department = request.user.hodprofile.department)
return qs
This also restricts the hod of a particular department to view only the contacts of his department and superuser to view all contact persons information.
This Contact table needs to be linked with the Workshop table as a many to many field, which will be covered in the next section.