Answer the question
In order to leave comments, you need to log in
Display model fields in django admin via list_display?
class ExampleModel(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
all_free_time = 0
class ExampleAdmin(admin.ModelAdmin):
model = ExampleModel
list_display = ("first_name", "last_name", "get_free_time")
@admin.display(ordering='all_free_time', description='Free hours')
def get_free_time(self, obj):
return obj.all_free_time
admin.site.register(ExampleModel, ExampleAdmin)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question