python - list filter by custom list display field in django admin -
i have following model admin. i'm displaying custom field in list view.
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 gives error "list_filter[0]' refers 'state' not refer field." want filter records state. how can in django 1.5?
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 should include list_filter if want filter
Comments
Post a Comment