django 自定义属性

mac2022-06-30  86

list_display 的元素也可以是属性。不过请注意,由于方式属性在Python 中的工作方式,在属性上设置short_description 只能使用 property() 函数,不能使用@property 装饰器。

class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) def my_property(self): return self.first_name + ' ' + self.last_name my_property.short_description = "Full name of the person" full_name = property(my_property) class PersonAdmin(admin.ModelAdmin): list_display = ('full_name',)

 

 

转载于:https://www.cnblogs.com/wangmin0216/p/5775181.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)