Django multiple profiles

Django -- Posted on Aug. 6, 2017

Django multiple profiles

              
                from django.db import models
from django.conf import settings

User = settings.AUTH_USER_MODEL


class Profile(models.Model):
    ACCOUNT_PENDING, ACCOUNT_APPROVED = range(2)
    USER_BASIC, USER_PREMIUM, USER_ENTERPRISE = range(3)
    ACCOUNT_STATUS = (
        (ACCOUNT_PENDING, 'pending'),
        (ACCOUNT_APPROVED, 'approved'),
    )
    PROFILE_CHOICES = (
        (USER_BASIC, 'Basic member'),
        (USER_PREMIUM, 'Premium member'),
        (USER_ENTERPRISE, 'Enterprise member'),

    )
    user = models.OneToOneField(User, on_delete=models.CASCADE,
                                primary_key=True)
    status = models.SmallIntegerField(choices=ACCOUNT_STATUS, default=0)
    profile_type = models.SmallIntegerField(choices=PROFILE_CHOICES, default=0)

    class Meta:
        default_related_name = 'profiles'
        verbose_name = 'profile'
        verbose_name_plural = 'profiles'

    def __str__(self):
        return 'Profile for user : {}'.format(self.user)
                  
   
            

Related Posts