You can use Q objects to preform OR queries. So it would look like this: from django.db.models import Q games = Game.objects.filter(Q(home_team=searchTeam) | Q(away_team=searchTeam)).filter(game_date__range(date_form.cleaned_data['startDate'], date_form.cleaned_data['endData'])).order_by('games_date', 'start_time')
On Jun 4, 10:55 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote: > Hi there. Long-time PHP developer now getting into Python and Django. > > I'm using the latest version of Django from SVN and are building a query > that does the following: > > Give me all the games where > homeTeam = searchTeam OR awayTeam = searchTeam > AND game_date is between start_date and end_date > ORDER BY game_date, start_date. > > Here's the code for it > > games = Game.objects.filter(home_team=searchTeam, > game_date__range=(date_form.cleaned_data['startDate'], > date_form.cleaned_data['endDate'])).order_by('game_date', 'start_time') | > Game.objects.filter(away_team=searchTeam, > game_date__range=(date_form.cleaned_data['startDate'], > date_form.cleaned_data['endDate'])).order_by('game_date', 'start_time') > > Now, it gets me the desired results but it just looks ugly. I'm wondering > if there is a better way to do this? I spent some time googling around for > answers but didn't find anything that could help me. > > Thanks in advance. > > -- > Chris Hartjes --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---