12
I want to be able to define a property in a Model that can also be displayed AND sort using admin_order_field in the 'list_display' Admin property. Below is the code for a property that I wanted to define (and be sortable in the django admin interface)
@property
def restaurant_name(self):
return str(self.restaurant)
restaurant_name.admin_order_field = 'restaurant__name'
However, I get the following error message:
AttributeError: 'property' object has no attribute 'admin_order_field'
When I get rid of the @property decorator, it works fine, but then I have to call restaurant_name() on model instances, instead of restaurant_name, which provides inconsistent style in how I access different properties of the model (which are actually defined as Python properties). How do I specify a Python property as sortable in the admin?