django - Get only the PK value, and return in from django table
问题描述
I want to search against the Tld
table, only get the primary key value of the Tld
object.
I have the code to perform a query to extract the whole row, but i only want the PK value matching the query:
Model.objects.filter(d=bu)
In plain sql what I'm trying to:
SELECT id from Model where d=<buv>
How can this be accomplished?
解决方案
我想你可能正在寻找这个:
Tld.objects.filter(d=base_url).values_list('id', flat=True)
推荐阅读
- javascript - Meteor - 将 new Function() 与“import”一起使用时出现“意外的令牌导入”
- python - 如何在数据框中按顺序添加值
- angular - Angular Material CheckBox 两种方式绑定
- theano - 在 PyMC3 中构建具有概率参数的多元正态分布
- javascript - 如何在浏览器上导入/导出 java-script 文件?
- java - 模拟距某个点设定距离的 GPS 路径
- apache-kafka - 如何验证用于 Kafka 的自签名 SSL 证书的到期日期?
- reactjs - 如何使用样式组件制作下拉菜单?
- apache-kafka - 偏移量如何保存在保存点中
- python - 使用 elasticsearch-py 关闭与 elasticsearch 集群的连接