use*_*875 9 django django-models
在这个链接中(对于ReadOnlyField):http://www.django-rest-framework.org/api-guide/fields/#readonlyfield它说"当包含与一个相关的字段名称时,默认情况下使用此字段与ModelSerializer属性而不是模型字段".话虽如此,你能给我一个模型字段名称的例子,它是一个"属性",一个模型字段名称是一个"字段"吗?
Rod*_*ier 21
在Django
,a model field
属于数据库中的列.另一方面,a model attribute
属于添加到a的方法或属性model
.
class MyModel(models.Model):
name = models.CharField()
quantity = models.IntegerField()
price = models.DecimalField()
@property
def description(self):
return '{}x of {}'.format(quantity, name)
def compute_total(self):
return quantity * price
Run Code Online (Sandbox Code Playgroud)
在上面的例子,name
,quantity
和price
被model fields
因为它们是在数据库的列.同时,description
和compute_total
是model attributes
.
归档时间: |
|
查看次数: |
4402 次 |
最近记录: |