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!
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()