On 25/04/2011 7:15am, Kenny Meyer wrote:
Hello guys,
In my application models I have two models, Judge and Participant:
Another way might be to use django groups. Have a participant group and
a judge group and pop your users into one or the other.
I prefer this approach for my own purposes because it means the user can
be either or both. When it comes right down to it they are both users.
Mike
from django.contrib.auth.models import User
class Judge(User):
pass
class Participant(User):
pass
In my view I want to find out if the authenticated user is either a
Judge or a Participant. How can I do that?
I have done the following, and it works most of the time for me:
def index(request):
user = request.user
if user.is_authenticated():
if user.is_superuser:
return redirect('/admin')
judge = None
participant = None
competition = None
try:
participant = user.participant or None
judge = user.judge or None
if participant:
competition = participant.competition
if judge:
competition = judge.competition
except Participant.DoesNotExist, e:
pass
except Judge.DoesNotExist, e:
pass
except Exception, e:
raise
# Do some more stuff...
But this is ugly. It would be cool if you could come up with better ideas.
Kenny
--
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.