On Jan 18, 12:43 pm, Darthmahon <cpma...@gmail.com> wrote:
> Hey Guys,
>
> I've got a model like this:
>
> event   = models.ForeignKey(Event)
> user            = models.ForeignKey(UserProfile)
> user_2  = models.ForeignKey(UserProfile, related_name='user_2')
>
> I then get a list of all the invites:
>
> people_invited = EventInvitation.objects.filter
> (event=event).select_related()
>
> And I want to check if a user is not in this list:
>
> user = UserProfile.objects.get(user=request.user.id)
> if not user in people_invited:
>         return HttpResponseRedirect('/')
>
> Now, the user will be in the user_2 field, not the user field, but the
> code above doesn't seem to work properly because even when the user is
> in the user_2 field they get redirected :/
>
> Any ideas?

You're lacking a bit of information here. What is EventInvitation? Is
it the model you posted above?

Assuming that, I would just get a list of ids of those users invited
and check the current id against that list:

people_invited = EventInvitation.objects.filter
(event=event).values_list('user_2_id', flat=True)
if not request.user.id in people_invited:
        return HttpResponseRedirect('/')

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to