To change how and what is displayed in the change list window, you can use the list_display version of ModelAdmin .
Keep in mind that columns specified in list_display , which are not real database fields, cannot be used for sorting, so you need to give the Django administrator a hint about which database field to actually use for sorting.
This is done by setting the admin_order_field attribute admin_order_field callee used to transfer some value to HTML, for example.
Example from Django docs for bright fields:
class Person(models.Model): first_name = models.CharField(max_length=50) color_code = models.CharField(max_length=6) def colored_first_name(self): return '<span style="color: #%s;">%s</span>' % ( self.color_code, self.first_name) colored_first_name.allow_tags = True colored_first_name.admin_order_field = 'first_name' class PersonAdmin(admin.ModelAdmin): list_display = ('first_name', 'colored_first_name')
I hope this helps.
Davor lucic
source share