mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-05 20:50:17 +03:00
Merge 4dc0301109
into 57eeef37d0
This commit is contained in:
commit
cedbde8718
|
@ -31,6 +31,7 @@ Alberto Sanchez / @alb3rto
|
|||
Eyad Al Sibai / @eyadsibai
|
||||
Chris Franklin
|
||||
Benjamin Abel
|
||||
Matt Warren / @mfwarren
|
||||
|
||||
* Possesses commit rights
|
||||
|
||||
|
|
|
@ -6,9 +6,27 @@ 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):
|
||||
create_form_class = UserCreationForm
|
||||
update_form_class = UserChangeForm
|
||||
form = MyUserChangeForm
|
||||
add_form = MyUserCreationForm
|
||||
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
|
Loading…
Reference in New Issue
Block a user