On Thu, Feb 5, 2009 at 10:25 AM, Ales Zoulek <ales.zou...@gmail.com> wrote:
> > Hi. > > Is there any way, how to easily redefine RelatedManager.get_query_set() > method? > > Here is an example situation: > > class Table(models.Model): > number = models.IntegerField() > > class Guest(models.Model): > confirmed = models.BooleanField() > table = models.ForeignKey(Table) > > objects = ConfirmedManager() > possible = models.Manager() > > > class ConfirmedManager(models.Manager): > def get_query_set(self): > super(ConfirmedManager, self).get_query_set().filter(confirmed=True) > > > > In that way, all queries on Guest.objects.all() will automaticly > filter only confirmed guests (unless specified by > Guest.possible.all()). > That's fine. > > But there is the trick: > > table_one = Table.objects.get(number=1) > table_one.guest_set.all() > > does not use the ConfirmedManager (and thus filter confirmed only > guests), but RelatedManager, whitch I'm not able to overwrite. > > Is there any way to do that? Or any other kind of implicit filtering? > > Thanks, > > Ales > > > > > PS: This is just a small examle, where the workaround to just apply > filter on every queryset is extremely simple. But my real-world case > is a lot bigger and more complicated, where explicit filtering on > every RelatedManager is far from nice and easy. > > > > > > -- > ------------------------------------------------------ > Ales Zoulek > +420 604 332 515 > Jabber: a...@jabber.cz > ICQ: 82647256 > ------------------------------------------------------ > > > > Yes, see how it's done here: http://docs.djangoproject.com/en/dev/topics/db/managers/#using-managers-for-related-object-access Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---