from django.contrib.auth.models import AbstractUser

from django.utils import timezone

import uuid, random, string

from datetime import timedelta

from app_account.msg_sender import send_otp



# region ==> custom user model

class CustomUser(AbstractUser):

    username = models.CharField(max_length=11, unique=True, verbose_name='شماره همراه')

    first_name = models.CharField(max_length=20, blank=True, null=True, verbose_name='نام')

    last_name = models.CharField(max_length=40, blank=True, null=True, verbose_name='نام خانوادگی')

    birth_date = models.DateField(blank=True, null=True, verbose_name='تاریخ تولد')



    def __str__(self) -> str:

        return f"{self.first_name} {self.last_name}"

    class Meta:

        db_table = 'tbl_user_info'

        verbose_name_plural = 'مشخصات کاربران'



from django.contrib import admin

from django.contrib.auth.admin import UserAdmin

from app_account.models import CustomUser, OTPRequest

from django.contrib.auth.models import Group



# hidden group models in panel admin

class HiddenGroupAdmin(admin.ModelAdmin):

  def has_module_permission(self, request):

    return False

admin.site.unregister(Group)

admin.site.register(Group, HiddenGroupAdmin)



# show new fild into user model and custom show user model in admin panel

class CustomUserAdmin(UserAdmin):

    model = CustomUser

    list_display = ['username', 'first_name', 'last_name', 'birth_date', 'email']



    fieldsets = (

        ('اطلاعات اصلی', {'fields': ('username', 'password')}),

        ('اطلاعات شخصی', {'fields': ('first_name', 'last_name', 'birth_date', 'email')}),

        # ('دسترسی‌ها', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),

        ('تاریخ‌ ورود و خروج', {'fields': ('last_login', 'date_joined')}),

    )

    add_fieldsets = (

        (None, {

            'classes': ('wide',),

            'fields': ('username', 'password1', 'password2', 'first_name', 'last_name', 'birth_date', 'email'),

        }),

    )

admin.site.register(CustomUser, CustomUserAdmin)



# change title and header admin panel

admin.site.site_header = 'پنل مدیریت سامانه طبیبان' 

admin.site.site_title = 'پنل مدیریت' 

admin.site.index_title = 'پنل مدیریت طبیبان' 

#############################



من کد بالا رو نوشتم و ارور زسر رو میگیرم غلتش چیه؟



SystemCheckError: System check identified some issues:



ERRORS:

app_account.CustomUser.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'app_account.CustomUser.groups' clashes with reverse accessor for 'auth.User.groups'.

        HINT: Add or change a related_name argument to the definition for 'app_account.CustomUser.groups' or 'auth.User.groups'.

app_account.CustomUser.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'app_account.CustomUser.user_permissions' clashes with reverse accessor for 'auth.User.user_permissions'.

        HINT: Add or change a related_name argument to the definition for 'app_account.CustomUser.user_permissions' or 'auth.User.user_permissions'.

auth.User.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'auth.User.groups' clashes with reverse accessor for 'app_account.CustomUser.groups'.

        HINT: Add or change a related_name argument to the definition for 'auth.User.groups' or 'app_account.CustomUser.groups'.

auth.User.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'auth.User.user_permissions' clashes with reverse accessor for 'app_account.CustomUser.user_permissions'.

        HINT: Add or change a related_name argument to the definition for 'auth.User.user_permissions' or 'app_account.CustomUser.user_permissions'.