Last active
December 25, 2015 02:49
-
-
Save nikolaygit/6905083 to your computer and use it in GitHub Desktop.
Add additional fields to the Django user profile.
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
# -*- coding: utf-8 -*- | |
from django.contrib import admin | |
from django.contrib.auth.admin import UserAdmin | |
from django.contrib.auth.models import User | |
from django.db import models | |
from .models import UserProfile | |
# enables editing the user profile in the Django admin | |
class UserProfileInline(admin.StackedInline): | |
model = UserProfile | |
can_delete = False | |
class UserAdmin(UserAdmin): | |
inlines = (UserProfileInline,) | |
admin.site.unregister(User) | |
admin.site.register(User, UserAdmin) |
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
# -*- coding: utf-8 -*- | |
from django.contrib.auth.models import User | |
from django.db import models | |
from filer.fields.image import FilerImageField | |
class UserProfile(models.Model): | |
user = models.OneToOneField(User, unique=True) | |
# add your fields here | |
image = FilerImageField(blank=True, null=True) |
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
# set the new user profile in your settings | |
AUTH_PROFILE_MODULE = 'yourapp.UserProfile' |
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
<!-- in your Django template you can access the additional fields for example like: user_instance.userprofile.image --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment