-
-
Save cdesch/4176252 to your computer and use it in GitHub Desktop.
Multiple Profiles for Internal/External Users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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