django models within models code example
Example 1: super in django manager
class DahlBookManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(author='Roald Dahl')
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=50)
objects = models.Manager()
dahl_objects = DahlBookManager()
Example 2: from django.db import models
from django.db import models
class Person(models.Model):
"""
This class creates a new table with
the name of your application and that class name.
The fully qualified name of the table
will be "appName_className".
Also, two fields with data type char will be
created: first_name and last_name.
"""
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)