db va type togirlandi
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .category import * # noqa
|
||||
from .products import * # noqa
|
||||
from .type import * # noqa
|
||||
|
||||
@@ -22,10 +22,6 @@ class FilialModel(AbstractBaseModel):
|
||||
|
||||
|
||||
class CategoryModel(AbstractBaseModel):
|
||||
class CategoryType(models.TextChoices):
|
||||
RESTAURANT = "RESTAURANT", _("Restaurant")
|
||||
BAR = "BAR", _("Bar")
|
||||
|
||||
filial = models.ForeignKey(
|
||||
FilialModel,
|
||||
verbose_name=_("filial"),
|
||||
@@ -35,11 +31,13 @@ class CategoryModel(AbstractBaseModel):
|
||||
blank=True,
|
||||
)
|
||||
name = models.CharField(verbose_name=_("name"), max_length=255)
|
||||
type = models.CharField(
|
||||
type = models.ForeignKey(
|
||||
"api.TypeModel",
|
||||
verbose_name=_("type"),
|
||||
max_length=20,
|
||||
choices=CategoryType.choices,
|
||||
default=CategoryType.RESTAURANT,
|
||||
related_name="categories",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
image = models.ImageField(verbose_name=_("image"), upload_to="categories/", null=True, blank=True)
|
||||
active_image = models.ImageField(
|
||||
@@ -49,7 +47,8 @@ class CategoryModel(AbstractBaseModel):
|
||||
|
||||
def __str__(self):
|
||||
filial_name = self.filial.name if self.filial else "Filial yo'q"
|
||||
return f"{self.name} ({self.type}) - {filial_name}"
|
||||
type_name = self.type.name if self.type else "Type yo'q"
|
||||
return f"{self.name} ({type_name}) - {filial_name}"
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
|
||||
20
core/apps/api/models/type.py
Normal file
20
core/apps/api/models/type.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
from django_core.models import AbstractBaseModel
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from model_bakery import baker
|
||||
|
||||
|
||||
class TypeModel(AbstractBaseModel):
|
||||
name = models.CharField(verbose_name=_("name"), max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
return baker.make(cls)
|
||||
|
||||
class Meta:
|
||||
db_table = "type"
|
||||
verbose_name = _("TypeModel")
|
||||
verbose_name_plural = _("TypeModels")
|
||||
Reference in New Issue
Block a user