Django - Include data from foreignkey in admin list_display function

前端 未结 3 1069
野的像风
野的像风 2021-01-20 03:48

I have two models and one admin model:

class Person(models.Model):

    firstname = models.CharField(maxlength=50)
    surname = models.CharField(maxlength=5         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 04:21

    You need to create something like this in your FriendAdmin class:

    class UserAdmin(admin.ModelAdmin):
        list_display = (..., 'get_reviews')
    
        def get_reviews(self, obj):
            return obj.book.review
        get_reviews.short_description = 'Review'
    

提交回复
热议问题