feat: added tags
This commit is contained in:
@@ -8,6 +8,7 @@ from shop.api.v1.viewsets import (
|
||||
OrderLineViewSet,
|
||||
ProviderViewSet,
|
||||
ProductBatchViewSet,
|
||||
TagViewSet,
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +18,7 @@ app_name = "shop"
|
||||
router = DefaultRouter()
|
||||
|
||||
router.register("taxes", TaxViewSet)
|
||||
router.register("tags", TagViewSet)
|
||||
router.register("customers", CustomerViewSet)
|
||||
router.register("providers", ProviderViewSet)
|
||||
router.register("products", ProductViewSet)
|
||||
|
||||
@@ -11,6 +11,7 @@ from shop.models import (
|
||||
Order,
|
||||
ProductBatch,
|
||||
Provider,
|
||||
Tag,
|
||||
)
|
||||
|
||||
|
||||
@@ -24,6 +25,15 @@ class TaxSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
|
||||
class TagSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Tag
|
||||
fields = (
|
||||
"id",
|
||||
"name",
|
||||
)
|
||||
|
||||
|
||||
class ProductPriceSerializer(serializers.ModelSerializer):
|
||||
tax = TaxSerializer()
|
||||
|
||||
@@ -60,6 +70,23 @@ class ProductSerializer(serializers.ModelSerializer):
|
||||
"is_digital_asset",
|
||||
"images",
|
||||
"price",
|
||||
"tags",
|
||||
)
|
||||
|
||||
|
||||
class ListProductSerializer(serializers.ModelSerializer):
|
||||
price = ProductPriceSerializer()
|
||||
tags = TagSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = (
|
||||
"name",
|
||||
"description",
|
||||
"stock",
|
||||
"is_digital_asset",
|
||||
"price",
|
||||
"tags",
|
||||
)
|
||||
|
||||
|
||||
@@ -98,6 +125,8 @@ class CreateProductSerializer(serializers.ModelSerializer):
|
||||
"url",
|
||||
"price",
|
||||
"tax",
|
||||
"tags",
|
||||
"images",
|
||||
)
|
||||
|
||||
|
||||
@@ -197,3 +226,5 @@ class OrderLineSerializer(serializers.ModelSerializer):
|
||||
"taxes",
|
||||
"tax_value",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ from shop.api.v1.serializers import (
|
||||
ProductBatchSerializer,
|
||||
CreateProductSerializer,
|
||||
CreateProductPriceSerializer,
|
||||
TagSerializer,
|
||||
ListProductSerializer,
|
||||
)
|
||||
from shop.models import (
|
||||
Product,
|
||||
@@ -30,6 +32,7 @@ from shop.models import (
|
||||
OrderLine,
|
||||
Provider,
|
||||
ProductBatch,
|
||||
Tag,
|
||||
)
|
||||
|
||||
from shop.api.v1.permissions import ProductPermissions, ProductPricePermissions
|
||||
@@ -46,6 +49,8 @@ class ProductViewSet(ModelViewSet):
|
||||
def get_serializer_class(self):
|
||||
if self.action == "create":
|
||||
return CreateProductSerializer
|
||||
elif self.action == "list":
|
||||
return ListProductSerializer
|
||||
return self.serializer_class
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
@@ -145,3 +150,8 @@ class OrderLineViewSet(ModelViewSet):
|
||||
.select_related("order")
|
||||
.filter(order__uuid=self.kwargs.get("order_id"))
|
||||
)
|
||||
|
||||
|
||||
class TagViewSet(ModelViewSet):
|
||||
serializer_class = TagSerializer
|
||||
queryset = Tag.objects.all()
|
||||
|
||||
Reference in New Issue
Block a user