You've already forked Promocode-API
mirror of
https://github.com/devitq/Promocode-API.git
synced 2026-05-22 22:07:12 +00:00
24 lines
591 B
Python
24 lines
591 B
Python
import uuid
|
|
|
|
from django.core.exceptions import ValidationError
|
|
from django.db import models
|
|
|
|
from config.errors import UniqueConstraintError
|
|
|
|
|
|
class BaseModel(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def save(self, *args, **kwargs) -> None: # noqa: ANN002, ANN003
|
|
self.full_clean(validate_unique=False)
|
|
|
|
try:
|
|
self.validate_unique()
|
|
except ValidationError as e:
|
|
raise UniqueConstraintError(e) from None
|
|
|
|
super().save(*args, **kwargs)
|