Re: Q lookup with both OR and AND

2007-09-06 Thread Nis Jørgensen
[EMAIL PROTECTED] skrev: > I'm having trouble piecing together a query for this model: > > class Ticket(models.Model): > ... > assigned_user = models.ForeignKey(User) > name = models.CharField(maxlength=255) > private = models.BooleanField(default=False) > > I'm trying to get all t

Re: Q lookup with both OR and AND

2007-09-06 Thread Nis Jørgensen
Michael Radziej skrev: > On Thu, Sep 06, [EMAIL PROTECTED] wrote: > > >> I thought I was close with this, but it only returned tickets assigned >> to me. (The parenthesis around the 2nd and 3rd Q's obviously didn't >> help) >> >> Ticket.objects.filter(Q(private__exact=False) | >> (Q(private__ex

Re: Q lookup with both OR and AND

2007-09-06 Thread Michael Radziej
On Thu, Sep 06, [EMAIL PROTECTED] wrote: > I thought I was close with this, but it only returned tickets assigned > to me. (The parenthesis around the 2nd and 3rd Q's obviously didn't > help) > > Ticket.objects.filter(Q(private__exact=False) | > (Q(private__exact=True) & Q(assigned_user__usernam

Re: Q lookup with both OR and AND

2007-09-05 Thread [EMAIL PROTECTED]
> Try replacing the ampersand with a comma and that /might/ do it. I tried this but it didn't work. I'm still getting tickets where private is true or false, and user is snewman: Ticket.objects.filter(Q(private__exact=False) | Q(private__exact=True), Q(assigned_user__username__exact='snewman'))

Re: Q lookup with both OR and AND

2007-09-05 Thread JustJohnny
It looks like your syntax is off a little: Try replacing the amersand with a comma and that /might/ do it. On Sep 5, 10:58 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm having trouble piecing together a query for this model: > > class Ticket(models.Model): > ... > assigned_use

Re: Q lookup with both OR and AND

2007-09-05 Thread Kevin Menard
Without looking into your problem in any real detail (sorry, late here), you could probably apply DeMorgan's Law and come up with a single predicate that you use throughout your query, using negation as appropriate. That may help you out. -- Kevin On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED