Created
May 9, 2018 14:26
-
-
Save anddam/dc08f5a991ed17dde5fb3c3c88dcfa0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profile(models.Model): | |
"""Extend User model """ | |
company = fields.CompanyField() | |
user = models.OneToOneField(to=User, on_delete=models.CASCADE) | |
timezone = fields.TimeZoneField(default=settings.DEFAULT_PROFILE_TIMEZONE) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
last_updated = models.DateTimeField(auto_now=True, editable=False) | |
class Meta: | |
ordering = ('-created',) | |
def __str__(self): | |
return 'Profile of %s' % self.user.username | |
def create_user_profile(sender, instance, created, **kwargs): | |
if created: | |
Profile.objects.create(user=instance) | |
models.signals.post_save.connect(create_user_profile, sender=User) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment