More than one profile in Django?

Posted by JPC on Stack Overflow See other posts from Stack Overflow or by JPC
Published on 2011-01-03T00:47:13Z Indexed on 2011/01/03 0:54 UTC
Read the original article Hit count: 224

Is it possible to use Django's user authentication features with more than one profile?

Currently I have a settings.py file that has this in it:

AUTH_PROFILE_MODULE = 'auth.UserProfileA'

and a models.py file that has this in it:

from django.db import models
from django.contrib.auth.models import User

class UserProfileA(models.Model):
    company = models.CharField(max_length=30)
    user = models.ForeignKey(User, unique=True)

that way, if a user logs in, I can easily get the profile because the User has a get_profile() method. However, I would like to add UserProfileB. From looking around a bit, it seems that the starting point is to create a superclass to use as the AUTH_PROFILE_MODULE and have both UserProfileA and UserProfileB inherit from that superclass. The problem is, I don't think the get_profile() method returns the correct profile. It would return an instance of the superclass. I come from a java background (polymorphism) so I'm not sure exactly what I should be doing.

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about django