Dimitris Kougioumtzis Blog About technology

Django multiple profiles

Category Django

Posted on Aug. 6, 2017



Django multiple profiles


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)

About

My name is Dimitris Kougioumtzis and i work as a Web developer at Rapidbounce Company

Elsewhere