Skip to content

Instantly share code, notes, and snippets.

@anddam
Created May 9, 2018 14:26
Show Gist options
  • Save anddam/dc08f5a991ed17dde5fb3c3c88dcfa0a to your computer and use it in GitHub Desktop.
Save anddam/dc08f5a991ed17dde5fb3c3c88dcfa0a to your computer and use it in GitHub Desktop.
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