Skip to content

Instantly share code, notes, and snippets.

@komly
Created September 5, 2016 20:48
Show Gist options
  • Select an option

  • Save komly/14181ee42c105c6a9d417f933ac31963 to your computer and use it in GitHub Desktop.

Select an option

Save komly/14181ee42c105c6a9d417f933ac31963 to your computer and use it in GitHub Desktop.
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
class Profile(models.Model):
website = models.URLField(_('website'), null=True, blank=True)
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='profile')
def __str__(self):
return self.website or ''
class Meta:
verbose_name = _('profile')
verbose_name_plural = _('profiles')
def create_profile(sender, instance, created, **kwargs):
if created:
profile = Profile(user=instance)
profile.save()
post_save.connect(create_profile, sender=settings.AUTH_USER_MODEL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment