Writing model managers
We now know that when we want to apply logic that pertains to a single object within a table, we will look into writing a model method. An advanced Django concept can allow us to add logic that would relate to the entire table of objects instead. That would be written using a model manager instead of a model method. By default, Django automatically creates a model manager for every model that you write. That manager is called the objects
manager, as in when we write a query statement such as MyModel.objects.all()
. Since the objects
manager is already created for us, there is technically no need for us to create a model manager at all. However, custom model managers can be used in a project to provide additional methods that the entire table uses. We will discuss a simple use of this concept that adds filters to a table. To learn more about how model managers can be used in more depth, visit the official Django documentation, found here: https://docs.djangoproject...