I have a table, in which some attributes are columns, and some are implemented as a 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.
I need to do something similar for a JsonField, eg
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.
How could I work around this?
也许一个简单的列表理解就可以满足您的要求:
[{"color": p["jsonproperties"]["color"]} for p in Product.objects.values("color")]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.