I tried to register the user, and I want to configure the admin site to have a permission field, groups field, etc. (Like in the picture)
but I have these errors like result:
Errors:
ERRORS:
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E012) There are duplicate field(s) in ‘fieldsets[1][1]’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E012) There are duplicate field(s) in ‘fieldsets[2][1]’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E012) There are duplicate field(s) in ‘fieldsets[3][1]’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E033) The value of ‘ordering[0]’ refers to ‘username’, which is not a field of ‘accounts.AppBaseUser’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E108) The value of ‘list_display[0]’ refers to ‘username’, which is not a callable, an attribute of ‘AppBaserUser’, or an attribute or method on ‘accounts.AppBaseUser’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E108) The value of ‘list_display[2]’ refers to ‘first_name’, which is not a callable, an attribute of ‘AppBaserUser’, or an attribute or method on ‘accounts.AppBaseUser’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E108) The value of ‘list_display[3]’ refers to ‘last_name’, which is not a callable, an attribute of ‘AppBaserUser’, or an attribute or method on ‘accounts.AppBaseUser’.
<class ‘beauty_salon_manage_sistem.accounts.admin.AppBaserUser’>: (admin.E116) The value of ‘list_filter[2]’ refers to ‘is_active’, which does not refer to a Field.
System check identified 8 issues (0 silenced).
This is my code:
`#admin:
@admin.register(AppBaseUser)
class AppBaserUser(UserAdmin):
add_form = RegistrationAppUserForm
# form = AppUserEditForm
fieldsets = (
(
None,
{
'fields': (
'email',
'password',
),
}),
(
'Personal info',
{
'fields': (
'first_name',
'last_name',
'email',
),
},
),
(
'Permissions',
{
'fields': (
'is_active',
'is_staff',
'is_superuser',
'groups',
'user_permissions',
),
},
),
(
'Important dates',
{
'fields': (
'last_login',
'date_joined',
),
},
),
)
def get_form(self, request, obj=None, **kwargs):
return super().get_form(request, obj, **kwargs)
#models:
class AppBaseUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
unique=True,
null=False,
blank=False,
)
is_staff = models.BooleanField(
default=True,
)
USERNAME_FIELD = 'email'
objects = AppBaseUserManager()
@property
def get_full_name_with_profile(self):
profile_full_name = AppStaffProfile.objects.get(pk=self.pk).get_full_name
if profile_full_name:
return f'{profile_full_name}'
return f'{self.email}'
def __str__(self):
if self.get_full_name_with_profile:
return self.get_full_name_with_profile
f'{self.email}'
class Meta:
verbose_name = 'User'
class AppStaffProfile(models.Model):
user = models.OneToOneField(AppBaseUser, primary_key=True, on_delete=CASCADE, )
MIN_LEN_FIRST_NAME = 2
MAX_LEN_FIRST_NAME = 40
MIN_LEN_LAST_NAME = 2
MAX_LEN_LAST_NAME = 40
MAX_LEN_POSITION = 100
first_name = models.CharField(
max_length=MAX_LEN_FIRST_NAME,
null=True,
blank=True,
validators=[
validators.MinLengthValidator(MIN_LEN_FIRST_NAME),
validate_only_letters,
]
)
last_name = models.CharField(
max_length=MAX_LEN_LAST_NAME,
null=True,
blank=True,
validators=[
validators.MinLengthValidator(MIN_LEN_LAST_NAME),
validate_only_letters,
]
)
position = models.CharField(
max_length=MAX_LEN_POSITION,
null=True,
blank=True,
)
@property
def get_full_name(self):
return f'{self.first_name} {self.last_name}'
def __str__(self):
if self.get_full_name:
return f'{self.get_full_name} - {self.position}'
return self.user.email
class Meta:
verbose_name = 'Staff'
#forms:
class RegistrationAppUserForm(UserCreationForm):
MIN_LEN_FIRST_NAME = 2
MAX_LEN_FIRST_NAME = 40
MIN_LEN_LAST_NAME = 2
MAX_LEN_LAST_NAME = 40
MAX_LEN_POSITION = 100
first_name = forms.CharField(
max_length=MAX_LEN_FIRST_NAME,
validators=[
validators.MinLengthValidator(MIN_LEN_FIRST_NAME),
validate_only_letters,
],
widget=forms.TextInput(attrs={'placeholder': 'First name'}),
required=True,
)
last_name = forms.CharField(
max_length=MAX_LEN_LAST_NAME,
validators=[
validators.MinLengthValidator(MIN_LEN_LAST_NAME),
validate_only_letters,
],
widget=forms.TextInput(attrs={'placeholder': 'Last name'}),
required=True,
)
position = forms.CharField(
max_length=MAX_LEN_POSITION,
widget=forms.TextInput(attrs={'placeholder': 'Position'}),
required=True,
)
password1 = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Password',
'label': 'Password'
}),
)
password2 = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Repeat password',
})
)
class Meta:
model = UserModel
fields = ('email',)
widgets = {
'email': forms.TextInput(attrs={
'placeholder': 'Enter your email',
}),
}
def cleaned_data_fist_name(self):
return self.cleaned_data['first_name']
def cleaned_data_last_name(self):
return self.cleaned_data['last_name']
def cleaned_data_position(self):
return self.cleaned_data['position']
def save(self, commit=True):
user = super().save(commit=commit)
profile = AppStaffProfile(
first_name=self.cleaned_data['first_name'],
last_name=self.cleaned_data['last_name'],
position=self.cleaned_data['position'],
user=user,
)
if commit:
profile.save()
return user
class AppProfileEditForm(UserChangeForm):
class Meta:
model = AppStaffProfile
fields = "__all__"
class AppUserEditForm(UserChangeForm):
class Meta:
model = UserModel
fields = ('email',)`
Can you help me, where is my mistake?