# Path: apps/user/models.py
# class UserProfile(models.Model):
#     TRIAL_USER = 1
#     PREMIUM_USER = 2
#     USER_STATUS = (
#         (TRIAL_USER, 'Free User'),
#         (PREMIUM_USER, 'Premium User'),
#     )
#     user = models.OneToOneField(settings.AUTH_USER_MODEL,
#                                 related_name='profile', primary_key=True)
#     subscription = models.IntegerField(choices=USER_STATUS, default=TRIAL_USER)
#     expired_date = models.DateTimeField(auto_now_add=True)
#     token = models.CharField(blank=True, max_length=255)
# 
#     class Meta:
#         db_table = 'user_profile'
# 
#     def __str__(self):
#         return self.user.email


from django.dispatch import receiver
from django.db.models.signals import post_delete, post_save
from django.contrib.auth.signals import user_logged_in
from django.conf import settings
from django.apps import apps
from string import digits
from random import choice
from apps.user.models import UserProfile




@receiver(post_save, sender=apps.get_model(settings.AUTH_USER_MODEL))
def create_user_profile(sender, instance, created, **kwargs):
    if not created:
        return

    token = ''.join(choice(digits) for i in range(6))
    token = instance.email + ':' + token


# Path: apps/user/models.py
# class UserProfile(models.Model):
#     TRIAL_USER = 1
#     PREMIUM_USER = 2
#     USER_STATUS = (
#         (TRIAL_USER, 'Free User'),
#         (PREMIUM_USER, 'Premium User'),
#     )
#     user = models.OneToOneField(settings.AUTH_USER_MODEL,
#                                 related_name='profile', primary_key=True)
#     subscription = models.IntegerField(choices=USER_STATUS, default=TRIAL_USER)
#     expired_date = models.DateTimeField(auto_now_add=True)
#     token = models.CharField(blank=True, max_length=255)
# 
#     class Meta:
#         db_table = 'user_profile'
# 
#     def __str__(self):
#         return self.user.email


# Path: apps/base/signals.py
from django.dispatch import receiver
from django.db.models.signals import post_delete, post_save
from django.contrib.auth.signals import user_logged_in
from django.conf import settings
from django.apps import apps
from string import digits
from random import choice
from apps.user.models import UserProfile





@receiver(post_save, sender=apps.get_model(settings.AUTH_USER_MODEL))
def create_user_profile(sender, instance, created, **kwargs):
    if not created:
        return

    token = ''.join(choice(digits) for i in range(6))
    token = instance.email + ':' + token


    profile = UserProfile.objects.create(user=instance, token=token)