# Path: fossevents/users/models.py
# class User(AbstractUser):
# 
#     is_moderator = models.BooleanField('active', default=False,
#                                        help_text='Designates whether this user is a moderator or not')
# 
#     objects = CustomUserManager()
# 
#     def __str__(self):
#         return self.username


from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from .models import User
# -*- coding: utf-8 -*-





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



# Path: fossevents/users/models.py
# class User(AbstractUser):
# 
#     is_moderator = models.BooleanField('active', default=False,
#                                        help_text='Designates whether this user is a moderator or not')
# 
#     objects = CustomUserManager()
# 
#     def __str__(self):
#         return self.username


# Path: fossevents/users/admin.py
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from .models import User

# -*- coding: utf-8 -*-





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)