@@ -0,0 +1,3104 @@
+from django import forms%0Afrom django.contrib import admin%0Afrom django.contrib.auth.models import Group%0Afrom django.contrib.auth.admin import UserAdmin%0Afrom django.contrib.auth.forms import ReadOnlyPasswordHashField%0A%0Afrom animal.models import MyUser%0A%0A%0Aclass UserCreationForm(forms.ModelForm):%0A    %22%22%22A form for creating new users. Includes all the required%0A    fields, plus a repeated password.%22%22%22%0A    password1 = forms.CharField(label='Password', widget=forms.PasswordInput)%0A    password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)%0A%0A    class Meta:%0A        model = MyUser%0A        fields = ('email', 'fb_access_token')%0A%0A    def clean_password2(self):%0A        # Check that the two password entries match%0A        password1 = self.cleaned_data.get(%22password1%22)%0A        password2 = self.cleaned_data.get(%22password2%22)%0A        if password1 and password2 and password1 != password2:%0A            raise forms.ValidationError(%22Passwords don't match%22)%0A        return password2%0A%0A    def save(self, commit=True):%0A        # Save the provided password in hashed format%0A        user = super(UserCreationForm, self).save(commit=False)%0A        user.set_password(self.cleaned_data%5B%22password1%22%5D)%0A        if commit:%0A            user.save()%0A        return user%0A%0A%0Aclass UserChangeForm(forms.ModelForm):%0A    %22%22%22A form for updating users. Includes all the fields on%0A    the user, but replaces the password field with admin's%0A    password hash display field.%0A    %22%22%22%0A    password = ReadOnlyPasswordHashField()%0A%0A    class Meta:%0A        model = MyUser%0A%0A    def clean_password(self):%0A        # Regardless of what the user provides, return the initial value.%0A        # This is done here, rather than on the field, because the%0A        # field does not have access to the initial value%0A        return self.initial%5B%22password%22%5D%0A%0A%0Aclass MyUserAdmin(UserAdmin):%0A    # The forms to add and change user instances%0A    form = UserChangeForm%0A    add_form = UserCreationForm%0A%0A    # The fields to be used in displaying the User model.%0A    # These override the definitions on the base UserAdmin%0A    # that reference specific fields on auth.User.%0A    list_display = ('email', 'fb_access_token', 'is_fb', 'fb_user_id', 'is_admin')%0A    list_filter = ('is_admin',)%0A    fieldsets = (%0A        (None, %7B'fields': ('email', 'password')%7D),%0A        ('Personal info', %7B'fields': ('fb_access_token',)%7D),%0A        ('Permissions', %7B'fields': ('is_admin',)%7D),%0A        ('Important dates', %7B'fields': ('last_login',)%7D),%0A    )%0A    # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin%0A    # overrides get_fieldsets to use this attribute when creating a user.%0A    add_fieldsets = (%0A        (None, %7B%0A            'classes': ('wide',),%0A            'fields': ('email', 'fb_access_token', 'password1', 'password2')%7D%0A        ),%0A    )%0A    search_fields = ('email',)%0A    ordering = ('email',)%0A    filter_horizontal = ()%0A%0A# Now register the new UserAdmin...%0Aadmin.site.register(MyUser, MyUserAdmin)%0A# ... and, since we're not using Django's builtin permissions,%0A# unregister the Group model from admin.%0A#admin.site.unregister(Group)%0A

add custom admin.py for management user