[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 the tickets where the tickets are not private OR
> the ticket is private and assigned to the current user.
>
> I'm foggy on where I use the comma, pipe, and ampersand characters to
> get the query structured properly. In pseudo-sql, I'd say "select *
> where private = False or (private=True and username='snewman')
>
> 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__username__exact='snewman')))
>   
I don't know why this does not work. Could it be that the db somehow
contains NULL's rather than False? Could you try the output of 
your_queryset._get_sql_clause()?

Anyway, since

A OR (NOT A AND B)
<=> (A OR NOT A) AND (A OR B)
<=> TRUE AND  (A OR B)
<=> A OR B

your query can be reduced to

Q(private__exact=False) | Q(assigned_user__username__exact='snewman')

Which is simpler, but probably does not work either.

Nis Jorgensen
No House IT.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to