Django multiple profiles using auth.User. Standard student teacher example

Is it correct way to create 2 profiles in django? I want student to have access to his teachers, and teacher to his students as well. I mean if I log in as a student, I want to browse exactly teachers who teach me, and if I log in as a teacher, I want to browse exactly students which I teach. That is way I rather can not create one profile for both teachers and students.

class Teacher(models.Model):
    ...
    user = models.OneToOneField(User)

class Student(models.Model):
    ...
    user = models.OneToOneField(User)
    teacher = models.ManyToManyField(Teacher)

if so, my AUTH_PROFILE_MODULE should look that way?

AUTH_PROFILE_MODULE = 'school.Teacher, school.Student'

would be grateful for any answers. Thanks!

Answers


You can make use of a single profile;

class People(models.Model):
    user = models.ForeignKey(User)
    teachers = models.ManyToManyField("self")

Then you can access the necessary information with;

teacher = People.objects.get(pk=<teacher_pk>)
students = People.objects.filter(teachers=teacher)

student = People.objects.get(pk=<student_pk>)
teachers = student.teachers.all()

Need Your Help

How does PHP know what type of variables it uses (or does it)?

php variables types vm-implementation

I haven't done much programing in many languages, but I know in C(++), you have to declare a variable type (int,char,etc).

JPA 2.0 and @Type annotation in Play Framework

jpa-2.0 jodatime playframework-2.0

I want to try out Joda Time with Play Framework 2.0. So I have this class called Release:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.