Using Request Info in Generic Views

0 views
Skip to first unread message

Keyton Weissinger

unread,
Jun 2, 2009, 7:33:00 AM6/2/09
to Django users
I know I'm in the minority, but I'm still having some trouble grokking
the details of generic views. I keep thinking I should be using them
but keep running into the same issue.

Here's my problem: I am building a mgmt site for schools in which
schools sign up for a monthly service fee. Most of my models have a
"school" foreign key which is also part of the user's profile.

So to see, for example, a list of teachers, I do something kind of
like this (assumes login has already occurred):

def myview(request):
current_person = request.user.get_profile()
current_school = current_person.school
teacher_list = Teacher.objects.filter(school=current_school)
etc

Almost everything I have has this school property.

My question is this: How do I leverage generic views in this capacity?
Is there a way to use the request information (specifically
request.user.get_profile().school in my case) in my urls.py when
generating my querysets?

Thank you!

Keyton

Keyton Weissinger

unread,
Jun 2, 2009, 7:35:04 AM6/2/09
to Django users

Sieker Adi Jörg

unread,
Jun 2, 2009, 8:54:51 AM6/2/09
to django...@googlegroups.com
Hi,

you can use this: http://docs.djangoproject.com/en/dev/topics/auth/#authentication-data-in-templates
to add the user to the template context.

Then you cold write template tags to actually get the data you need
using the user template variable. http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags

adi
Reply all
Reply to author
Forward
0 new messages