Commit 7ce6d5d153d0a50e810f90411b1198440a6d88d3

Authored by Sergio Oliveira
1 parent 1d609e2a

Adding admin classes for custom user

Showing 1 changed file with 54 additions and 0 deletions   Show diff stats
src/accounts/admin.py 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +
  2 +from django import forms
  3 +from django.contrib import admin
  4 +from django.contrib.auth.admin import UserAdmin
  5 +
  6 +from .models import User
  7 +
  8 +
  9 +class UserCreationForm(forms.ModelForm):
  10 + class Meta:
  11 + model = User
  12 + fields = ('username', 'email')
  13 +
  14 + def __init__(self, *args, **kwargs):
  15 + super(UserCreationForm, self).__init__(*args, **kwargs)
  16 + self.fields['email'].required = True
  17 +
  18 +
  19 +class UserChangeForm(forms.ModelForm):
  20 + class Meta:
  21 + model = User
  22 + fields = ('username', 'first_name', 'last_name', 'email', 'is_active',
  23 + 'is_staff', 'is_superuser', 'groups', 'last_login',
  24 + 'date_joined', 'twitter', 'facebook', 'google_talk',
  25 + 'webpage')
  26 +
  27 + def __init__(self, *args, **kwargs):
  28 + super(UserChangeForm, self).__init__(*args, **kwargs)
  29 + self.fields['email'].required = True
  30 +
  31 +
  32 +
  33 +class MyUserAdmin(UserAdmin):
  34 + form = UserChangeForm
  35 + add_form = UserCreationForm
  36 +
  37 + fieldsets = (
  38 + (None, {'fields': ('username',)}),
  39 + ('Personal info', {'fields': ('first_name', 'last_name', 'email',
  40 + 'twitter', 'facebook', 'google_talk',
  41 + 'webpage')}),
  42 + ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups')}),
  43 + ('Important Dates', {'fields': ('last_login', 'date_joined')})
  44 + )
  45 +
  46 + add_fieldsets = (
  47 + (None, {
  48 + 'classes': ('wide',),
  49 + 'fields': ('username', 'email')}
  50 + ),
  51 + )
  52 +
  53 +
  54 +admin.site.register(User, MyUserAdmin)
... ...