mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-09 16:10:49 +03:00
addresses issue mentioned here: https://code.djangoproject.com/ticket/19353
adding users in admin resulted in reference to auth.User
This commit is contained in:
parent
c243085d8c
commit
e29879d813
|
@ -6,9 +6,27 @@ from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
|
||||||
from .models import User
|
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):
|
class UserAdmin(AuthUserAdmin):
|
||||||
create_form_class = UserCreationForm
|
form = MyUserChangeForm
|
||||||
update_form_class = UserChangeForm
|
add_form = MyUserCreationForm
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user