Monday, June 18, 2012

Re: Trying to find something in multiple databases... Confused...

well -- I hit the wrong key and posted that before I was finished typing...

here's what's in my views.py file:
def index(request)
     current_username = os.environ['REMOTE_USER']

This should provide me with their username (yes I do have 'import os' at the top of the file)...

Now, after I get their username I want to do something like this (but I'm not sure how to write in django -- so I've put ## around the pseudo-code)
     try:
         student = Student.objects.get(student_name=current_username)
     except (#can't find it in Student database, but I don't know what code to put here#)
         try:
             instructor = Instructor.objects.get(instructor_name=current_username)
         except (#can't find it in Instructor database, but I don't know what code to put here#)
               try:
                    administrator = Administrator.objects.get(administrator_name=current_username)
               except (#fail condition - can't find current_username in Administrator database, but I don't know what code to put here#)
                    #because we failed to find it in any database, we assume it's a student and add it
                    student = Student(student_name=current_username)
                    student.save
     #here's where I'm not sure how to continue -- I want to do something like this#
     #if student is defined#
          return render_to_response('ta/student.html', student)
     #else if instructor is defined#
          return render_to_response('ta/instructor.html', instructor)
     #else if administrator is defined#
          return render_to_response('ta/administrator.html', administrator)

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate