How to show all fields of model in admin page?

后端 未结 11 513
無奈伤痛
無奈伤痛 2021-01-30 16:25

here is the models page

In this picture, only the title shows up on here, I used:

 def __unicode__(self):
        return self.title;  

11条回答
  •  不思量自难忘°
    2021-01-30 16:53

    If you want to include all fields without typing all fieldnames, you can use

    list_display = BookAdmin._meta.get_all_field_names()
    

    The drawback is, the fields are in sorted order.

    Edit:

    This method has been deprecated in Django 1.10 See Migrating from old API for reference. Following should work instead for Django >= 1.9 for most cases -

    list_display = [field.name for field in Book._meta.get_fields()]
    

提交回复
热议问题