user2237822 user2237822 - 3 years ago 163
Python Question

Student vs Teacher

I am coding a model in Django.

I am using the User model from django.contrib.auth.models

I need to create a teacher entity and student entity.

They are basically the same - they all required username, password, email except for student type = 'student' and type = 'teacher'

How can I represent the Teacher and Student models?

Should I be extending User model for both the teacher and student?
or should I just create one model extending from the User model that just has a different type for student and teacher.


I have

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

class Teacher(Profile):
salary = models.FloatField()

class Student(Profile)
grade = models.FloatField()

Where User refers to the User model in django.contrib.auth.models

Answer Source

There is nothing wrong with what you have, it's a valid patten: please read this tho: it's a good read and explains Model Inheritance in more detail. Read on multi-table inheritance and abstract models too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download