Question: How do i get a list of all id/primary key for a table. Say i have this table:

```
class Blog(models.Model)
  title = models.CharField()
  body = models.CharField()
  author = models.ForeignKey(Author)

```

assume the field *author* is an Author object. I want to get all the ids of Blog where author=author

i know i can use 

```
    blogs = Blog.objects.filter(author=author)

```

and get all the blog objects in a list form, but how do i get the list IDS/PK? Similar to "Select id from Blog where Author=author"

Answer: 
You can do this using [`values_list`](https://docs.djangoproject.com/en/stable/ref/models/querysets/#values-list) method.

```
blogs = Blog.objects.filter(author=author).values_list('id', flat=True)

```

See more at the [Django queryset documentation](https://docs.djangoproject.com/en/stable/ref/models/querysets/#values-list).
[`values_list`](https://docs.djangoproject.com/en/stable/ref/models/querysets/#values-list) it returns tuples when iterated over. Each tuple contains the value from the respective field or expression passed into the values\_list().

```
author = Blog.objects.filter(author=author)
ids    = author.values_list('pk', flat=True)

# list method get ids without parse the returning queryset

print(list(ids))

```