-
|
I'd like to add I tried like in the following code but it didn't work. When I call |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
I think I'm seeing the same thing for this scenario: This call doesn't use the SubclassFeedManager() at all. |
Beta Was this translation helpful? Give feedback.
-
|
Can somebody please suggest a workaround for this issue? I also want the custom manager to be called on each of the child classes when you call the base class custom manager. |
Beta Was this translation helpful? Give feedback.
-
|
Hello @fed239 thanks for your question - sorry its been a decade for someone to get back to you! There are a few concepts to understand here. First - the difference between a manager and a queryset.
There are several ways to specify custom managers and querysets:
1 and 2 are functionally equivalent - Applying this to your code you could write: class MyBaseQuerySet(PolymorphicQuerySet):
def filter_by_user(self, user):
return self.all()
class MyBaseModel(PolymorphicModel):
...
objects = MyBaseQuerySet.as_manager()
class MyChild1QuerySet(MyBaseQuerySet):
def filter_by_user(self, user):
return self.filter(fieldA__lt=user.profile.propA)
class MyChild1Model(MyBaseModel):
fieldA = models.IntegerField()
...
objects = MyChild1QuerySet.as_manager()
class MyChild2QuerySet(MyBaseQuerySet):
def filter_by_user(self, user):
return self.filter(fieldB__gt=user.profile.propB)
class MyChild2Model(MyBaseModel):
fieldB = models.IntegerField()
...
objects = MyChild2QuerySet.as_manager()@dsummersl your example code does work. I tested it against the current release - it looks like a PR fixing this problem was added in 2013: #33 |
Beta Was this translation helpful? Give feedback.
Hello @fed239 thanks for your question - sorry its been a decade for someone to get back to you!
There are a few concepts to understand here. First - the difference between a manager and a queryset.
Model.objectsis a Manager instance. Methods on that manager instance may returnQuerySetinstances (e.g. all). Which brings me to the first point:QuerySet- the methods you add to thatQuerySetwill not be available on the manager by default unless you create a manager class from the QuerySet.There are several ways to specify custom managers and querysets: