首页 > 解决方案 > 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?

标签: djangodata-extraction

解决方案


我想你可能正在寻找这个:

Tld.objects.filter(d=base_url).values_list('id', flat=True)

推荐阅读