[Answer]-Have custom manager but keep objects keyword available

1đź‘Ť

âś…

Managers provide Methods for table-wide operations (referring to the table of the model they are added to).
So if you want to write a manager for your City model it would be best pratice to call it CityManager.

Since custom managers inherit from models.Manager, you can overwrite the objects name in your model class. This won’t change the behaviour of the standard objects manager, but your custom methods will also be available under the objects name.

See the documentation for more details:
https://docs.djangoproject.com/en/1.8/topics/db/managers/#custom-managers

And please pay attention to the distinction between Managers and Model methods,latter ones are for “row-level” functionality as explainded in the documentation.

👤cbergmiller

Leave a comment