1# First, define the Manager subclass.
2class DahlBookManager(models.Manager):
3 def get_queryset(self):
4 return super().get_queryset().filter(author='Roald Dahl')
5
6# Then hook it into the Book model explicitly.
7class Book(models.Model):
8 title = models.CharField(max_length=100)
9 author = models.CharField(max_length=50)
10
11 objects = models.Manager() # The default manager.
12 dahl_objects = DahlBookManager() # The Dahl-specific manager.
13
1# First, define the Manager subclass.
2class DahlBookManager(models.Manager):
3 def get_queryset(self):
4 return super().get_queryset().filter(author='Roald Dahl')
5
6# Then hook it into the Book model explicitly.
7class Book(models.Model):
8 title = models.CharField(max_length=100)
9 author = models.CharField(max_length=50)
10
11 objects = models.Manager() # The default manager.
12 dahl_objects = DahlBookManager() # The Dahl-specific manager.
13Book.dahl_objects.all()
14Book.dahl_objects.filter(title='Matilda')
15Book.dahl_objects.count()