Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Profile model one-to-one with User
- Loading branch information
1 parent
f5d4e74
commit 41ee7b0
Showing
8 changed files
with
49 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
from django.contrib.auth.models import User | ||
|
||
from accounts.models import Profile | ||
|
||
class ProfileInline(admin.TabularInline): | ||
model = Profile | ||
can_delete = False | ||
verbose_name_plural = 'profile' | ||
|
||
class UserAdmin(admin.ModelAdmin): | ||
inlines = (ProfileInline, ) | ||
|
||
admin.site.unregister(User) | ||
admin.site.register(User, UserAdmin) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(settings.AUTH_USER_MODEL) | ||
bio = models.TextField(blank=True) | ||
def __unicode__(self): | ||
return self.user.get_full_name() | ||
|
||
# Signal handlers | ||
@receiver(post_save, sender=User) | ||
def user_post_save_callback(sender, **kwargs): | ||
created = kwargs['created'] | ||
instance = kwargs['instance'] | ||
if created: | ||
profile = Profile(); | ||
profile.user = instance | ||
profile.save() |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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