Re: Chaining custom manager methods on querysets
Thanks a lot for the explanation. Now it is much clearer for me... On 21 Eylül, 19:18, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > On 9/21/07, omat <[EMAIL PROTECTED]> wrote: > This: > > > class TagManager(models.Manager) > > # ... > > def get_query_set(self): > > return TagQuerySet > > Should be this: > def get_query_set(self): > return TagQuerySet(Tag) > >And you'll obviously need to implement "my_filter" on TagQuerySet. > > Also, this: >def my_filter(self): ># calculate the query set ># ... >return get_query_set().my_filter(*args, **kwargs > > Should be this: >def my_filter(self): ># calculate the query set ># ... >return self.get_query_set().my_filter(*args, **kwargs) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Chaining custom manager methods on querysets
On 9/21/07, omat <[EMAIL PROTECTED]> wrote: This: > class TagManager(models.Manager) > # ... > def get_query_set(self): > return TagQuerySet Should be this: def get_query_set(self): return TagQuerySet(Tag) And you'll obviously need to implement "my_filter" on TagQuerySet. Also, this: def my_filter(self): # calculate the query set # ... return get_query_set().my_filter(*args, **kwargs Should be this: def my_filter(self): # calculate the query set # ... return self.get_query_set().my_filter(*args, **kwargs) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Chaining custom manager methods on querysets
Ok, I solved the recursive import problem and tried to improve my understanding of what is going on. Now I have: class TagManager(models.Manager): def get_query_set(self): return TagQuerySet class Tag(models.Model): # ... objects = TagManager() class TagQuerySet(models.query.QuerySet): model = Tag When I try to access the manager, I get the following exception: "unbound method get() must be called with TagQuerySet instance as first argument (got nothing instead)" I think this means "the get_query_set should return an instance of the TagQuerySet". But Malcolm states in the post mentioned above: > Sub-class the QuerySet class and have your model's manager return your > subclass as the result of get_query_set() rather than the current > QuerySet instance that is returned. Can anyone tell me how to do this? Thanks... On 21 Eylül, 11:19, omat <[EMAIL PROTECTED]> wrote: > Hi, > > I have a custom manager for a Tag model and I want to apply its > methods also to Tag querysets, not just to "Tag.objects". > > There has been a discussion on this > here:http://groups.google.com/group/django-users/browse_thread/thread/3d00... > > but what Malcolm suggested is not very clear to me. I think I get it > wrong, but here is what I've tried: > > class TagQuerySet(models.query.Query): > model = Tag > > class TagManager(models.Manager) > # ... > def get_query_set(self): > return TagQuerySet > > def my_filter(self): > # calculate the query set > # ... > return get_query_set().my_filter(*args, **kwargs) > > I doubt that this will work, but in the first place I have a circular > reference problem while importing. TagQuery class needs Tag to be > defined, Tag needs TagManager to be defined and TagManager needs > TagQuery to be defined. > > Thanks for any help... > oMat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Chaining custom manager methods on querysets
Google ate my previous post, so I'm re-posting... I solved the recursive import problem and tried to improve my understanding of what is going on. Now I have: class TagManager(models.Manager): def get_query_set(self): return TagQuerySet class Tag(models.Model): # ... objects = TagManager() class TagQuerySet(models.query.QuerySet): model = Tag When I try to access the manager, I get the following exception: "unbound method get() must be called with TagQuerySet instance as first argument (got nothing instead)" I think this means "the get_query_set should return an instance of the TagQuerySet". But Malcolm states in the post mentioned above: > Sub-class the QuerySet class and have your model's manager return your > subclass as the result of get_query_set() rather than the current > QuerySet instance that is returned. Can anyone tell me how to do this? Thanks... On 21 Eylül, 11:19, omat <[EMAIL PROTECTED]> wrote: > Hi, > > I have a custom manager for a Tag model and I want to apply its > methods also to Tag querysets, not just to "Tag.objects". > > There has been a discussion on this > here:http://groups.google.com/group/django-users/browse_thread/thread/3d00... > > but what Malcolm suggested is not very clear to me. I think I get it > wrong, but here is what I've tried: > > class TagQuerySet(models.query.Query): > model = Tag > > class TagManager(models.Manager) > # ... > def get_query_set(self): > return TagQuerySet > > def my_filter(self): > # calculate the query set > # ... > return get_query_set().my_filter(*args, **kwargs) > > I doubt that this will work, but in the first place I have a circular > reference problem while importing. TagQuery class needs Tag to be > defined, Tag needs TagManager to be defined and TagManager needs > TagQuery to be defined. > > Thanks for any help... > oMat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Chaining custom manager methods on querysets
Hi, I have a custom manager for a Tag model and I want to apply its methods also to Tag querysets, not just to "Tag.objects". There has been a discussion on this here: http://groups.google.com/group/django-users/browse_thread/thread/3d00660409d277da/ but what Malcolm suggested is not very clear to me. I think I get it wrong, but here is what I've tried: class TagQuerySet(models.query.Query): model = Tag class TagManager(models.Manager) # ... def get_query_set(self): return TagQuerySet def my_filter(self): # calculate the query set # ... return get_query_set().my_filter(*args, **kwargs) I doubt that this will work, but in the first place I have a circular reference problem while importing. TagQuery class needs Tag to be defined, Tag needs TagManager to be defined and TagManager needs TagQuery to be defined. Thanks for any help... oMat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---