sergzach
sergzach

Reputation: 6754

How to select a post with no comments?

How to create the such query by a standart way (not using raw SQL)?

Then I need to add more conditions.

E.g.

class Post( models.Model ):
    title = models.CharField( max_length = 128 )
    text = models.TextField()

class Comment( models.Model ):
    post = models.ForeignKey( Post )
    text = models.TextField()

Upvotes: 0

Views: 37

Answers (1)

falsetru
falsetru

Reputation: 369134

Specify comment with None:

Post.objects.filter(comment=None)

You can add more conditions using addtional filter or exclude.

Upvotes: 2

Related Questions