Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple Profiles for Internal/External Users
from django.db import models
from django.contrib.auth import User
from mycompany.models import Client
from userprofiles.models import Profile
class External(Profile):
#External-specific models
client = models.ForeignKey(Client)
def __unicode__(self):
return "%s" % self.user.get_full_name()
from django.db import models
from django.contrib.auth import User
from userprofiles.models import Profile
class Associate(Profile):
#Associate-specific fields
employeeid = models.PositiveIntegerField(editable=False)
def __unicode__(self):
return "%s" % self.user.get_full_name()
class Client(models.Model):
name = models.CharField(max_length=75)
def __unicode__(self):
return "%s" % self.name
from django.db import models
from django.contrib.auth.models import User
USER_TYPES = {
('INT', _('Internal')),
('EXT', _('External')),
}
class Profile(models.Model):
user = models.OneToOneField(User, unique=True)
#Other Basic Fields
about = models.TextField()
user_type = models.CharField(max_length=3, choices=USER_TYPES, default='INT')
def __unicode__(self):
return "%s" % self.user.get_full_name()
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from models import Profile
def create_profile(sender, **kw):
user = kw["instance"]
if kw["created"]:
profile = Profile(user=user)
profile.save()
post_save.connect(create_profile, sender=User, dispatch_uid="user-profile-signal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.