diff --git a/core/apps/api/admin/products.py b/core/apps/api/admin/products.py index 66673b7..3a2e6bd 100644 --- a/core/apps/api/admin/products.py +++ b/core/apps/api/admin/products.py @@ -10,7 +10,7 @@ class SubProductInline(TabularInline): @admin.register(ProductsModel) class ProductsAdmin(ModelAdmin): - list_display = ("id", "name", "price", "image", "subcategory", "created_at") + list_display = ("id", "name", "price", "order", "subcategory", "created_at") list_filter = ("subcategory__category__filial", "subcategory__category", "subcategory", "created_at") search_fields = ("name", "subcategory__name", "subcategory__category__name") list_select_related = ("subcategory", "subcategory__category", "subcategory__category__filial") diff --git a/core/apps/api/admin/type.py b/core/apps/api/admin/type.py index 3b5738c..0efccb5 100644 --- a/core/apps/api/admin/type.py +++ b/core/apps/api/admin/type.py @@ -5,7 +5,7 @@ from django.contrib import admin @admin.register(TypeModel) class TypeAdmin(ModelAdmin): - list_display = ("id", "name", "get_filials") + list_display = ("id", "name", "percent", "get_filials") filter_horizontal = ("filials",) def get_filials(self, obj): diff --git a/core/apps/api/migrations/0013_typemodel_percent_productsmodel_order.py b/core/apps/api/migrations/0013_typemodel_percent_productsmodel_order.py new file mode 100644 index 0000000..0615cf9 --- /dev/null +++ b/core/apps/api/migrations/0013_typemodel_percent_productsmodel_order.py @@ -0,0 +1,29 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0012_typemodel_filials'), + ] + + operations = [ + migrations.AddField( + model_name='typemodel', + name='percent', + field=models.DecimalField(decimal_places=2, default=0.0, max_digits=5, verbose_name='percent'), + ), + migrations.AddField( + model_name='productsmodel', + name='order', + field=models.PositiveIntegerField(default=0, verbose_name='order'), + ), + migrations.AlterModelOptions( + name='productsmodel', + options={ + 'ordering': ['order'], + 'verbose_name': 'ProductsModel', + 'verbose_name_plural': 'ProductsModels', + }, + ), + ] diff --git a/core/apps/api/models/products.py b/core/apps/api/models/products.py index a46cd8f..8b1c583 100644 --- a/core/apps/api/models/products.py +++ b/core/apps/api/models/products.py @@ -3,7 +3,6 @@ from django.utils.translation import gettext_lazy as _ from django_core.models import AbstractBaseModel from model_bakery import baker - from core.apps.api.models.category import SubcategoryModel @@ -18,6 +17,7 @@ class ProductsModel(AbstractBaseModel): on_delete=models.CASCADE, ) description = models.TextField(verbose_name=_("description"), null=True, blank=True) + order = models.PositiveIntegerField(verbose_name=_("order"), default=0) def __str__(self): return self.name @@ -30,6 +30,7 @@ class ProductsModel(AbstractBaseModel): db_table = "products" verbose_name = _("ProductsModel") verbose_name_plural = _("ProductsModels") + ordering = ["order"] class SubProductModel(AbstractBaseModel): diff --git a/core/apps/api/models/type.py b/core/apps/api/models/type.py index d3df708..8135a55 100644 --- a/core/apps/api/models/type.py +++ b/core/apps/api/models/type.py @@ -6,6 +6,7 @@ from model_bakery import baker class TypeModel(AbstractBaseModel): name = models.CharField(verbose_name=_("name"), max_length=255) + percent = models.DecimalField(verbose_name=_("percent"), max_digits=5, decimal_places=2, default=0.0) filials = models.ManyToManyField( "api.FilialModel", verbose_name=_("filials"), diff --git a/core/apps/api/serializers/products/products.py b/core/apps/api/serializers/products/products.py index 17a91cd..e3db09b 100644 --- a/core/apps/api/serializers/products/products.py +++ b/core/apps/api/serializers/products/products.py @@ -31,6 +31,7 @@ class BaseProductsSerializer(serializers.ModelSerializer): "type", "price", "image", + "order", "subcategory", "subproducts", ] @@ -45,6 +46,7 @@ class ListProductsSerializer(BaseProductsSerializer): "type", "price", "image", + "order", "subcategory", ] @@ -62,4 +64,5 @@ class CreateProductsSerializer(BaseProductsSerializer): "description", "price", "image", + "order", ] diff --git a/core/apps/api/serializers/type/type.py b/core/apps/api/serializers/type/type.py index b1c7fb9..b9c6b58 100644 --- a/core/apps/api/serializers/type/type.py +++ b/core/apps/api/serializers/type/type.py @@ -7,7 +7,7 @@ class BaseTypeSerializer(serializers.ModelSerializer): class Meta: model = TypeModel - fields = ["id", "name", "filials"] + fields = ["id", "name", "percent", "filials"] class ListTypeSerializer(BaseTypeSerializer): @@ -26,4 +26,4 @@ class CreateTypeSerializer(BaseTypeSerializer): ) class Meta(BaseTypeSerializer.Meta): - fields = ["id", "name", "filials"] + fields = ["id", "name", "percent", "filials"]