restore composer.json, add mysqli extension
This commit is contained in:
@@ -1,15 +1,56 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.vendors.models import VendorproductModel, VendorModel, CategoryModel, SectionModel
|
||||
from core.apps.vendors.models import (
|
||||
VendorproductModel,
|
||||
VendorModel,
|
||||
CategoryModel,
|
||||
SectionModel,
|
||||
ProductVariantModel,
|
||||
ProductAttributeModel
|
||||
)
|
||||
|
||||
|
||||
from core.apps.vendors.serializers.vendor_product.ProductImage import ListProductimageSerializer
|
||||
|
||||
|
||||
class ProductVariantSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductVariantModel
|
||||
fields = [
|
||||
"id",
|
||||
"firestore_id",
|
||||
"price",
|
||||
"sku",
|
||||
"quantity",
|
||||
"image_url",
|
||||
"attribute_data",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
attr_data = ret.get("attribute_data")
|
||||
|
||||
if attr_data and isinstance(attr_data, list):
|
||||
# Resolve attribute names
|
||||
resolved_data = []
|
||||
for item in attr_data:
|
||||
if isinstance(item, dict):
|
||||
a_id = item.get("attribute_id")
|
||||
if a_id:
|
||||
# Try to get the name from the cache or DB
|
||||
attr_obj = ProductAttributeModel.objects.filter(firestore_id=a_id).first()
|
||||
item["attribute_name"] = attr_obj.name if attr_obj else "Unknown"
|
||||
resolved_data.append(item)
|
||||
ret["attribute_data"] = resolved_data
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
class BaseVendorproductSerializer(serializers.ModelSerializer):
|
||||
category = serializers.SlugRelatedField(slug_field='firestore_id', queryset=CategoryModel.objects.all(), required=False, allow_null=True)
|
||||
section = serializers.SlugRelatedField(slug_field='firestore_id', queryset=SectionModel.objects.all(), required=False, allow_null=True)
|
||||
images = ListProductimageSerializer(many=True, read_only=True)
|
||||
variants = ProductVariantSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = VendorproductModel
|
||||
@@ -27,7 +68,9 @@ class BaseVendorproductSerializer(serializers.ModelSerializer):
|
||||
"is_publish",
|
||||
"image",
|
||||
"images",
|
||||
"variants",
|
||||
"photos_json",
|
||||
"product_specification",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
||||
3
core/apps/vendors/urls.py
vendored
3
core/apps/vendors/urls.py
vendored
@@ -1,7 +1,7 @@
|
||||
from django.urls import include, path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views import CategoryView, ProductimageView, VendorproductView, VendorView, SectionView
|
||||
from .views import CategoryView, ProductimageView, VendorproductView, VendorView, SectionView, ProductAttributeView
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("sections", SectionView, basename="sections")
|
||||
@@ -9,4 +9,5 @@ router.register("categories", CategoryView, basename="categories")
|
||||
router.register("vendors", VendorView, basename="vendors")
|
||||
router.register("products", VendorproductView, basename="products")
|
||||
router.register("product-images", ProductimageView, basename="product-images")
|
||||
router.register("attributes", ProductAttributeView, basename="attributes")
|
||||
urlpatterns = [path("", include(router.urls))]
|
||||
|
||||
15
core/apps/vendors/views/Attribute.py
vendored
Normal file
15
core/apps/vendors/views/Attribute.py
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
from rest_framework import viewsets, permissions
|
||||
from core.apps.vendors.models import ProductAttributeModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class ProductAttributeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductAttributeModel
|
||||
fields = ["id", "firestore_id", "name"]
|
||||
|
||||
|
||||
class ProductAttributeView(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = ProductAttributeModel.objects.all()
|
||||
serializer_class = ProductAttributeSerializer
|
||||
permission_classes = [permissions.AllowAny]
|
||||
1
core/apps/vendors/views/__init__.py
vendored
1
core/apps/vendors/views/__init__.py
vendored
@@ -2,3 +2,4 @@ from .category import * # noqa
|
||||
from .vendor import * # noqa
|
||||
from .vendor_product import * # noqa
|
||||
from .section import * # noqa
|
||||
from .Attribute import * # noqa
|
||||
|
||||
Reference in New Issue
Block a user