我正在尝试使用agreement_vendors_merchandise_list__merchandise_unique_id
将不可读的字段some_alias
重命名为extra
,但是出现Uknown column "agreement_vendors_merchandise_list__merchandise_unique_id"
错误,但如果我不使用任何别名,则所有没关系。我究竟做错了什么 ?我可以将extra
与select_selected
一起使用吗?
orders_qs = Order.objects.select_related('agreement_vendors_merchandise_list')\
.extra(select={'some_alias': 'agreement_vendors_merchandise_list__merchandise_unique_id'})\
.values('some_alias')
模特:
class Order(models.Model):
agreement_vendors_merchandise_list = models.ForeignKey(AgreementVendorsMerchandiseList,
on_delete = models.CASCADE,
related_name = 'agreement_vendors_merchandise_list')
class AgreementVendorsMerchandiseList(models.Model):
merchandise_unique = models.ForeignKey(MerchandiseUnique,
on_delete = models.CASCADE,
related_name = 'pricelist_merchandise_unique')
更新:
此代码(不带别名)完美无缺:
orders_qs = Order.objects.select_related('agreement_vendors_merchandise_list')\
.values('agreement_vendors_merchandise_list__merchandise_unique_id')