[英]Django: SELECT JsonField AS new_name?
I have a table, in which some attributes are columns, and some are implemented as a postgres JsonField. 我有一个表,其中一些属性是列,而某些属性实现为postgres JsonField。
For the columns, I can write eg 对于列,我可以写例如
Product.objects.values(brand=F('brand_name'))
for implement a SELECT brand_name AS brand
query. 用于实现SELECT brand_name AS brand
查询。
I need to do something similar for a JsonField, eg 我需要对JsonField做类似的事情,例如
Product.objects.values(color=F('jsonproperties__color'))
However, the F
expressions do not work correctly with JsonFields, and there doesn't seem to be a fix coming anytime soon. 但是, F
表达式不能与JsonFields 一起正常使用,并且似乎很快也不会修复。
How could I work around this? 我该如何解决?
也许一个简单的列表理解就可以满足您的要求:
[{"color": p["jsonproperties"]["color"]} for p in Product.objects.values("color")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.