Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.utils import timezone
- from django.contrib.auth.models import AbstractUser
- from django.contrib.postgres.fields import JSONField
- from django.conf import settings
- from django.utils.translation import ugettext_lazy as _
- # from django.contrib.auth.models import User
- import string, random
- from datetime import datetime, timedelta
- import pytz
- from ceexlo.custom_codes import GENDER, ETHNICITY
- from timezone_field import TimeZoneField
- class User(AbstractUser):
- GENDER = GENDER
- ETHNICITY = ETHNICITY
- avatar = models.CharField(max_length=2048, blank=True, default='/static/img/ressources/user.png')
- ip = models.CharField(max_length=32, blank=True, editable=False)
- tel = models.CharField(max_length=32, blank=True)
- postal_address = models.CharField(max_length=255, blank=True)
- postal_address_2 = models.CharField(max_length=255, blank=True)
- city = models.CharField(max_length=64, blank=True)
- country = models.CharField(max_length=64, blank=True)
- zip_code = models.CharField(max_length=5, blank=True)
- lang = models.CharField(max_length=8, choices=settings.LANG_SUPPORTED, default='en')
- birth_date = models.DateField(null=True, blank=True)
- gender = models.IntegerField(choices=GENDER, null=True, blank=True)
- ethnicity = models.IntegerField(choices=ETHNICITY, null=True, blank=True)
- timezone = TimeZoneField(default='UTC')
- data = JSONField(default={}, blank=True, null=True)
- options = JSONField(default={}, blank=True, null=True)
- last_update = models.DateTimeField()
- @property
- def full_name(self):
- return f'{self.first_name} {self.last_name}'
- def save(self, *args, **kwargs):
- self.last_update = datetime.now(pytz.timezone("UTC"))
- if self.username == '' or self.username == None:
- self.username = self.email
- super(User, self).save(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement