mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-24 15:30:44 +03:00
34 lines
867 B
Python
34 lines
867 B
Python
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.contrib import admin
|
|
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
|
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
|
|
|
|
from .models import User
|
|
|
|
|
|
class MyUserChangeForm(UserChangeForm):
|
|
class Meta(UserChangeForm.Meta):
|
|
model = User
|
|
|
|
|
|
class MyUserCreationForm(UserCreationForm):
|
|
class Meta(UserCreationForm.Meta):
|
|
model = User
|
|
|
|
def clean_username(self):
|
|
username = self.cleaned_data["username"]
|
|
try:
|
|
User.objects.get(username=username)
|
|
except User.DoesNotExist:
|
|
return username
|
|
raise forms.ValidationError(self.error_messages['duplicate_username'])
|
|
|
|
|
|
class UserAdmin(AuthUserAdmin):
|
|
form = MyUserChangeForm
|
|
add_form = MyUserCreationForm
|
|
|
|
|
|
admin.site.register(User, UserAdmin)
|