add product
This commit is contained in:
1 parent
423d4cf40e
commit
c8d45dd07c
58 files changed
+8309
-674
No files matched your search
@@ -1,6 +1,8 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
|
||||
from utils.base_model import BaseModel
|
||||
from django.core.exceptions import ValidationError
|
||||
from utils.validations.mobile import normalize_mobile
|
||||
import uuid
|
||||
|
||||
|
||||
@@ -8,9 +10,11 @@ class CUserManager(BaseUserManager):
|
||||
def create_user(self, username, password, **extra_fields):
|
||||
if not username:
|
||||
raise ValueError("Please Enter username")
|
||||
extra_fields['mobile'] = normalize_mobile(extra_fields.get('mobile'))
|
||||
user = self.model(username=username, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
user.full_clean()
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, username, password, **extra_fields):
|
||||
@@ -31,6 +35,7 @@ class CUser(BaseModel, AbstractBaseUser, PermissionsMixin):
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
REQUIRED_FIELDS = ['mobile']
|
||||
|
||||
objects = CUserManager()
|
||||
|
||||
@@ -44,3 +49,9 @@ class CUser(BaseModel, AbstractBaseUser, PermissionsMixin):
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name_family} - {self.username}'
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
self.mobile = normalize_mobile(self.mobile)
|
||||
if type(self).objects.filter(mobile=self.mobile).exclude(pk=self.pk).exists():
|
||||
raise ValidationError({"mobile": "کاربری با این شماره موبایل قبلاً ثبت شده است."})
|
||||
Reference in new issue
Block a user