> On Apr 6, 2016, at 9:41 PM, Sudhanshu Shekhar <sudshekha...@gmail.com> wrote:
> 
> Hi,
> 
> I am creating a tutor-student forum using Django. For which I need to have 
> two different user profiles, one for students and one for teachers. However, 
> I am unsure about the best way to do this. I am currently following the below 
> approach:
> 
> class UserProfile:
>  user = models.OneToOneField(User, reverse_name="profile")
>  #other common Attributes
>  class Meta(object):
>    abstract = true
> 
> class TutorProfile():
>  #tutor fields
>  class Meta(object):
>    abstract = true
> 
> class StudentProfile():
>   #student fields
>   class Meta(object):
>    abstract = true
> 
> class Profile(TutorProfile, StudentProfile, UserProfile):
>   pass
> 
> 
> The idea is taken from the Django best practices book. However, I am curious 
> if there is any other way with lesser space usage. Any thoughts?
> 
> PS: I also asked the same question on stackoverflow : 
> http://stackoverflow.com/questions/36404889/django-multiple-user-profiles-with-class-based-views-best-practices
>  but didn't get any responses.


First of all, I don’t like multiple inheritance.  You are in control of all of 
the parent classes, so it might not blow up in your face, but there still night 
be problems down the line.  Second, I think this might be the same as just 
creating a single class with all of the fields, so there’s no reason to create 
three abstract classes for it to inherit from.

How old is the Django best practices book you are using?  Because starting with 
1.5, you should be using a custom User model 
<https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#auth-custom-user>
 instead of a constant profile.

What I would do, and I’d love to hear some debate about it, is put most (or 
all, depending on requirements) of the fields from the UserProfile in the new 
custom user model, and have two not-abstract profiles with one-to-one fields to 
the user.  If the things in UserProfile don’t make sense for all users, then 
make three profiles which all point to the custom user model.

Peter of the Norse
rahmc...@radio1190.org



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D4629C3B-5B67-439B-B6B7-0EA2CC7CDFF5%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to