models obejct indjango code example
Example 1: and in django query filter
Blog.objects.filter(entry__headline__contains='Lennon', entry__pub_date__year=2008)
Example 2: super in django manager
# First, define the Manager subclass.
class DahlBookManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(author='Roald Dahl')
# Then hook it into the Book model explicitly.
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=50)
objects = models.Manager() # The default manager.
dahl_objects = DahlBookManager() # The Dahl-specific manager.