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.
Michal
signature.asc
Description: Digital signature