from django.db import models class Student(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) age = models.IntegerField() # exclude all students who are over 18 years old students = Student.objects.exclude(age__gt=18)
from django.db import models class Product(models.Model): name = models.CharField(max_length=255) price = models.DecimalField(max_digits=10, decimal_places=2) available = models.BooleanField(default=True) discount = models.BooleanField(default=False) # exclude all products that are out of stock and not discounted products = Product.objects.filter(available=False, discount=False).exclude()The exclude method can be used with a variety of conditions to achieve your filtering needs. The django.db.models QuerySet is part of the Django package library.