Search code examples
djangodata-extraction

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?


Solution

  • I think you're perhaps looking for this:

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