On Mon, May 16, 2011 at 10:21 PM, Michal Petrucha <michal.petru...@ksp.sk>wrote:
> On Mon, May 16, 2011 at 09:58:40PM +0200, Marc Aymerich wrote: > > Hi Swawm. > > Thanks for your answer. > > > > when I call Model.objects.active_during(Q(Q(ini=some_date, end=some_date) > | > > Q(ini=other_date, fin=other_date))) I get This error: > > > > > > active_during() takes exactly 3 arguments (2 given) > > > > > > > > this is my code: > > > > class OrderQuerySet(models.query.QuerySet): > > def active_during(self, ini, end): > > return self.filter(Q(register_date__lte = end) & > > Q(Q(cancel_date__isnull=True) | Q(cancel_date__gte = > ini > > ))) > > > > class OrderManager(models.Manager): > > # Custom managers with chainable filters. > > # Based on: http://djangosnippets.org/snippets/562/ > > > > def __init__(self, qs_class=models.query.QuerySet): > > super(OrderManager,self).__init__() > > self.queryset_class = qs_class > > > > def get_query_set(self): > > return self.queryset_class(self.model) > > > > def __getattr__(self, attr, *args): > > try: return getattr(self.__class__, attr, *args) > > except AttributeError: return getattr(self.get_query_set(), attr, > > *args) > > > > > > Seems to me that I need to define active_during() like: > > def active_during(self, *args, **kwargs) > > > > and make some custom stuff if a Q() object is passed to the method. But > what > > I need to do? > In this example, the active_during method is supposed to take two > positional parameters, a start date and an end date. It then creates > the required Q object structure required to represent a filter for > you. What you're doing is passing it one parameter already containing > a Q filter. That is something you'll usually want to pass to a filter, > exclude or get method. Hi Michal, Yep, this is actually what I want to do, pass a Q() object to the active_during() method. My question is, how the active_during method should be in order to work with a Q() object passed as a parameter? sorry if I wasn't clear in my firts mail. -- Marc -- 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.