Created
September 5, 2016 20:48
-
-
Save komly/14181ee42c105c6a9d417f933ac31963 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
| 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