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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -