Skip to content

Instantly share code, notes, and snippets.

@nikolaygit
Last active December 25, 2015 02:49
Show Gist options
  • Save nikolaygit/6905083 to your computer and use it in GitHub Desktop.
Save nikolaygit/6905083 to your computer and use it in GitHub Desktop.
Add additional fields to the Django user profile.
# -*- 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)
# -*- 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)
# set the new user profile in your settings
AUTH_PROFILE_MODULE = 'yourapp.UserProfile'
<!-- 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