我想在模板上使用get_status_display,它来自一个只包含模型中一些字段的查询集。在
我有一个带有选择字段(状态)的模型。在
class Operation(models.Model, ModelMixin):
operation_area = models.ForeignKey('operations.OperationArea', null=True)
created = models.DateTimeField(auto_now=True)
indication = models.NullBooleanField()
observation = models.TextField(blank=True, null=True)
rate = models.IntegerField(blank=True, null=True)
scheduling = models.DateTimeField(blank=True, null=True)
status = models.IntegerField(choices=OPERATION_TYPE)
class OperationArea(models.Model, ModelMixin):
campaign = models.ForeignKey('campaigns.Campaign')
person = models.ForeignKey('registrations.Person')
user = models.ForeignKey('authentication.User')
area = models.CharField(max_length=1, choices=OPERATION_AREA)
我的问题是:
^{pr2}$从这里得到一个get a dict,但是get_FOO_dislpay是一个实例方法,不适用于dict。我不想使用.only(),因为他带来了操作区域对象,并获得人名他又问了一句手术区.人名。有什么想法,如何使用一个查询和得到邱福龙显示?在
我认为annotate()正是您所需要的。在
您应该使用:
看看https://docs.djangoproject.com/en/2.0/ref/models/querysets/#annotate。在
相关问题 更多 >
编程相关推荐