How to display an attribute of a foreign key in the Django admin page

前端 未结 3 437
独厮守ぢ
独厮守ぢ 2021-01-18 17:34

I want to display the level field of the category to which the product is related on the object\'s admin page.

    class Category(m         


        
3条回答
  •  自闭症患者
    2021-01-18 17:48

    In your admin.py file

    class ProductAdmin(admin.ModelAdmin):
        list_display = ('name', 'category__level', 'category')
    
    admin.site.register(Product, ProductAdmin)
    

    Try this.............

提交回复
热议问题