You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a custom model manager that extends InheritanceManager like so:
class Manager(InheritanceManager):
def custom_method(self):
return self.filter(...)
because the return type of get_queryset() of InheritanceManagerMixin is hardcoded to return self._queryset_class(self.model) it's impossible for me to chain the methods of my custom Manager:
Model.objects.all().custom_method() will fail since .all() will return an instance of InheritanceQuerySet and my custom_method isn't defined there, it's rather defined on Manager.
Although this slight confusion is mentioned in the documentation here it's still not clear for the user how to properly extend InheritanceManager with custom managers
Environment
Django Model Utils version: 4.1.1
Django version: 3.2.11
Python version: 3.8
Code examples
Model.objects.custom_method() works Model.objects.filter().custom_method() fails with exception 'InheritanceQuerySet' object has no attribute 'custom_method'
The text was updated successfully, but these errors were encountered:
This way I retain djano-model-util InheritanceManager functionality and allow for chaining custom methods defined on the queryset, I still think this should be made more clear for the user in the documentation, because directly inheriting from InheritanceManager seems to cause problems
Problem
I am using a custom model manager that extends
InheritanceManager
like so:because the return type of
get_queryset()
ofInheritanceManagerMixin
is hardcoded to returnself._queryset_class(self.model)
it's impossible for me to chain the methods of my customManager
:Model.objects.all().custom_method()
will fail since.all()
will return an instance ofInheritanceQuerySet
and mycustom_method
isn't defined there, it's rather defined onManager
.Although this slight confusion is mentioned in the documentation here it's still not clear for the user how to properly extend
InheritanceManager
with custom managersEnvironment
Code examples
Model.objects.custom_method()
worksModel.objects.filter().custom_method()
fails with exception'InheritanceQuerySet' object has no attribute 'custom_method'
The text was updated successfully, but these errors were encountered: