Hello,

I'm a developer for a Polish NGO, owning 5 schools in Warsaw. My
organization decided to throw out our antiquated custom PHP intranet
system (everything school needs: timetables, grades, reports,
announcements, forums, etc. ) and design a brand new one using Django.
And to Open Source it. I hope we will do a good job, since it's our
first project in Django. Anyway, here is our question:

There will be 3 distinct types of users: teachers, students and
parents. Each type needs model with different fields extending the
User model (for example only parent has ManyToMany relationship with
students, to connect him with his children, and only student has a
ForeignKey connecting him to a class etc.).

Given a User instance we need to be able to easily check for its
account type (teacher/student/parent) and then to retrieve appropriate
fields. What is the best way to design this models?

I can think of at least 3 ways to do this, but I don't know if any of
them really make sense. For example we can have a simple field with
account type in user's profile and then separate Student, Teacher, and
Parent models, each with a one-to-one field pointing back at user
model. It would allow us to do things like this:

profile = request.user.get_profile()
if profile.objects.account_type == 'parent':
    children = request.user.parent.children

Another idea is to make a subclass of the User model for every type of
account. It would work very similarly to the example above (are there
any pros or cons of this method?)

We could also use a generic relationship connecting user profile to
appropriate account type model (either Teacher, Student or Parent). We
could then have instance methods with common names for all three
models, for example instance method get_type() would return "student"
for Student model and "teacher" for teacher model, and instance method
get_schools() would return list of schools user is linked to (one of
requirement for the system is support for multiple schools; every
account is linked with schools in different way - student can only be
in one school at the time, but teacher can work in many schools, and
parent is linked to all schools his kids are attend. That's why you
need
an instance method, different for every model). The code could work
like that (granted that generic relationship's field name is "type"):

account_type = request.user.type.get_type()
if account_type == 'parent':
    children = request.user.type.children
elif account_type == 'student':
     class = request.user.type.class

and also:

schools = request.user.type.get_schools() # schools linked to this
account

So, is there a proper way to do this?

Thanks,
Ludwik
--~--~---------~--~----~------------~-------~--~----~
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