I'm trying to construct complex queries, to better use the database
(fewer hits, less slowdown).

The models:
List model, has a boolean called Public.
Item model, is related to the List model via foreign key.
Visibility model, is related to the Item model via foreign key, and
has information like first name, last name, and email, and a visible
boolean.

I'm trying to be able to eliminate all the items with visibility
constraints attached to them for anonymous users via this, but it
doesn't look quite right:

if user.is_anonymous():
        #gets all the items with no visibility constraints.
        items = ListItem.objects.filter(WList__exact=wlist_id).exclude
(visibility__isnull=True)

If the user is not anonymous, I need to either do a match with the
first name, last name, or the email, and then exclude all of those
with Visibility.Visible=False for the match. (Implicitly, that leaves
all the items with the Visible=True match for this specific user) I
figure, then that I just need to use the query above ORed with the
query for all the items without visibility constraints. Here's what I
have... is it right?

else:
        #first get all items with specific viewing for this specific
user
        items = ListItem.objects.filter(WList__exact=wlist_id)
        items.filter(Q(visibility__FirstName__iexact=user.first_name)
| Q(visibility__LastName__iexact=user.last_name) | Q
(visibility__Email__iexact=user.email))
        items.exclude(visibility__Visible__exact=False)
        items = items | ListItem.objects.filter
(WList__exact=wlist_id).exclude(visibility__isnull=True)

Thank you for your help, in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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