November 2015
Beginner to intermediate
840 pages
26h 30m
English
A manager is any Python class that inherits from the Manager class defined in Django’s db.models package. Django automatically generates a manager for a model class unless the objects attribute is explicitly declared.
To create and connect our custom PostManager, we simply declare it as a subclass of Manager and then add it as the objects attribute on Post. In Example 24.1, we also add the published() method to find all Post objects with a pub_date from before today’s date, much like the published() method defined in Tag and Startup.
Example 24.1: Project Code
1 from datetime import date . ... 14 class PostManager(models.Manager): 15 16 ...
Read now
Unlock full access