users/models.py

24 lines
684 B
Python
Raw Normal View History

2020-01-26 20:47:33 +01:00
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
import pytz
# GENERAL Methods and Classes
#
def get_userprofile(user):
try:
profile = user.userprofile
except UserProfile.DoesNotExist:
profile = UserProfile(user=user)
profile.save()
return profile
# USERPROFILE Model
#
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE)
timezone = models.CharField(max_length=150, default='UTC', choices=[(t, t) for t in pytz.common_timezones])
language_code = models.CharField(max_length=150, default='en', choices=settings.LANGUAGES)