django-models - How to get the specific field of foreignkey using values function in Django?
问题描述
Suppose Foo, Entry are two Django models, and foo is a foreignkey in Entry. The Django QuerySet Api says that,If you have a field called foo that is a foreignkey, the default values() call will return a dictionary key called foo_id( https://docs.djangoproject.com/en/dev/ref/models/querysets). My question is how to get the specific field of foreignkey foo by values()? That is, if FIELDS is a field of fool,when I get a dictionary list of Entry, how to show FIELDS in the return dictionary, not the foo_id?
解决方案
您可以使用双下划线来表示外键的字段:
Entry.objects.values('foo__FIELDS')
推荐阅读
- arrays - 对六进制数组元素进行分组
- vue.js - 将 null 设置为默认值时 DatePicker Vuetify 错误
- python - 比较两个数据框并输出新列
- com - 在哪里可以找到 Microsoft Javascript 中函数 GetObject 的文档?
- elasticsearch - 从 ElasticSearch 中删除特定文档?
- xml - 如何使用 XSLT 和 Python 将 xml 的子子元素移动到新的 xml 文件?
- jqgrid - 为什么我的 JqGrid 在我更改问题类型时会缩小?
- mysql - Azure MySQL Workbench 8.0.25 DDL 搞砸了
- python - 如何在 Excel 中读取公式并将其转换为在 Python 中进行计算?
- laravel - 如何在 Laravel 中发出 SOAP 请求?