Django: Faking a field in the admin interface?

后端 未结 4 2037
轻奢々
轻奢々 2021-01-30 19:00

I have a model, Foo. It has several database properties, and several properties that are calculated based on a combination of factors. I would like to present these

4条回答
  •  暖寄归人
    2021-01-30 19:18

    You can use the @property decorator in your model (Python >= 2.4):

    class Product(models.Model):
    
        @property
        def ranking(self):
            return 1
    

    "ranking" can then be used in list_display:

    class ProductAdmin(admin.ModelAdmin):
        list_display = ('ranking', 'asin', 'title')
    

提交回复
热议问题