mcastle
mcastle

Reputation: 2982

Why use custom Querysets instead of custom model Managers?

It seems like much of what can be done by a custom Queryset can be accomplished by a model Manager. So why use custom Querysets instead of model Managers?

Upvotes: 0

Views: 37

Answers (1)

Lorenzo Peña
Lorenzo Peña

Reputation: 2263

Custom querysets allow for chaining methods, while custom managers only let you access defined methods directly from the manager. If you need to expose methods from the manager and the queryset, you can use Queryset.as_manager.

Take a look at: https://docs.djangoproject.com/en/1.9/topics/db/managers/#create-manager-with-queryset-methods

Upvotes: 2

Related Questions