Answer the question
In order to leave comments, you need to log in
How Exclude works with OneToMany binding?
Let the application have the following models:
##models.py
from django.db import models
class Blog(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Entry(models.Model):
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
headline = models.CharField(max_length=255)
pub_date = models.DateField()
def __str__(self):
return self.headline
Blog.objects.filter(entry__headline__contains='lennon', entry__pub_date__year=2008)
Blog.objects.exclude(entry__headline__contains="lennon", entry__pub_date__year=2008)
Blog.objects.exclude(entry__in=Entry.objects.filter(headline__contains="lennon", pub_date__year=2008))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question