Hi! I have a calendar that permits multiple selections of dates.
My view has to filter the data depending on the selected dates. I am unsure about how I can construct a query that filters correctly the data. I construct my list of datetime objects like this: list = request.session['selected_dates'].split(',') date_list = [datetime.datetime(int(mydate.split('/')[2]), int(mydate.split('/')[0]), int(mydate.split('/')[1])) for mydate in list] If I only have one date in my list, this works: qdates = Q(mydatetimefield__year=date_list[0].year, mydatetimefield__month=date_list[0].month, mydatetimefield__day=date_list[0].day) myqueryset = myqueryset.filter(qdates) #I am modifying an existing queryset The problem stems of the need to assign new values to my Q object dynamically. I have tried this, but it does not work. (It will always filter only to the first selected date): qdates = Q() for myfinaldate in date_list: qdates |= Q(**{"mydatetimefield__year": myfinaldateyear}) qdates &= Q(**{"mydatetimefield__month": myfinaldate.month}) qdates &= Q(**{"mydatetimefield__day": myfinaldate.day}) First I would want to know if there is a better way to lookup data that is IN a range of data? Second I would want to know if I can somehow add to my Q object a mix of groups of ANDed values that are ORed between them? I hope this makes sense to somebody, Stefan ;) PS: If I only filter by the day, for example, it works: qdates = Q() for myfinaldate in date_list: qdates &= Q(**{"mydatetimefield__day": myfinaldate.day}) This will give me all objects that match the selected DAY. That means if I select January, 27, I'll get data from January, December, November, 27.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---