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"
not_authored_blog = Author.objects.exclude(blog__id__in=blogs)
. i have another table which has FK to 'blog' and want to get the objects in the other table that is not FK in 'blog'. more complicated than that thoughblog_set
related manager has any records; if its empty, then this Author has no blogs. It will be a lot better than doing your exclude query, which might be translated as a largeNOT IN
clause.