Hello guys,

In my application models I have two models, Judge and Participant:

  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.

Reply via email to