I extended the user with extra option, such as department. But when i try adding filter for the derpartment at the admin panel. It throws this error:
ERRORS: : (admin.E116) The value of 'list_filter[0]' refers to 'department', which does not refer to a Field.
Refrence to how it looks: https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#extending-user
With this addition:
class UserAdmin(BaseUserAdmin):
inlines = (EmployeeInline, )
list_display = ('username', 'email', 'first_name', 'last_name', 'get_department')
list_filter = ('department',)
def get_department(self, instance):
return instance.employee.department
List display seems work fine.
User model has relationship with Employee Model so you can access it From user Table with employee field. employee is now the field of user.
list_filter = ('employee__department',)
employee is the Model. and department is the field of Employee. hopes it should work for you My one is working below is the screen shot the that.
You have to specify which model department
is in.
list_filter = ('employee__department',)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With