mystand wrote:
> I need to do a query that selects all Events that a logged in user can edit.
> They can edit an event if they are in the default group, if they are in any
> of the other groups, or they are one of the users added to the event. 

first of all, it might be easier if you follow the database convention of 
naming your tables in singular.  in this case, your events model should be 
called 'Event' and not 'Events'.  that makes it more readable when you use 
singular in ForeignKey fields and plural in ManyToManyField's

in your case, the general strategy is to use Q() objects.  the idea is to 
define each possibility separately and then join them all with the '|' 
operator.  something like this (untested):

@login_required
def editable_groups(request):
        user = request.user
        evs_by_defgroup = Q(default_group__in=user.group_set)
        evs_by_groups = Q(group__in=user.group_set)
        evs_by_users = user.events_set

        myevents = Events.objects.filter (evs_by_defgroup | evs_by_groups | 
evs_by_users)
        return render_to_response ("template.html", {'myevents':myevents})


(i'm not sure about '|'ing the Q() objects with the queryset 'user.events_set', 
but i don't know how to express this as a Q() object)


-- 
Javier

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.


Reply via email to