How to show all fields of model in admin page?

后端 未结 11 634
無奈伤痛
無奈伤痛 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:50

    The problem with most of these answers is that they will break if your model contains ManyToManyField or ForeignKey fields.

    For the truly lazy, you can do this in your admin.py:

    from django.contrib import admin
    from my_app.models import Model1, Model2, Model3
    
    
    @admin.register(Model1, Model2, Model3)
    class UniversalAdmin(admin.ModelAdmin):
        def get_list_display(self, request):
            return [field.name for field in self.model._meta.concrete_fields]
    

提交回复
热议问题