List filter by user list display field in django admin

I have the following model administrator. I display the custom field as a list.

class CustomerAdmin(admin.ModelAdmin): list_display = ('first_name', 'last_name', 'email', 'state') search_fields = ('first_name', 'last_name', 'email') list_filter = ('state',) def state(self, obj): address = Address.objects.filter(owner=obj.id) if address: return address.state return None 

I tried above, but it gives the error “list_filter [0]” refers to a “state” that does not apply to the field. Therefore, I want the movie records to be recorded by state. So, how can I do this in django 1.5 ?

+5
source share
1 answer
 class CustomerAdmin(admin.ModelAdmin): list_display = ('first_name', 'last_name', 'email', 'state') list_filter = ('state',) search_fields = ('first_name', 'last_name', 'email') def state(self, obj): address = Address.objects.filter(owner=obj.id) if address: return address.state return None 

You must enable list_filter if you want to filter

-1
source

Source: https://habr.com/ru/post/1231919/


All Articles