fix: minor API adjustments
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django.utils import timezone
|
||||
from rest_framework import serializers
|
||||
|
||||
from files.api.v1.serializers import FileUploadSerializer
|
||||
from files.api.v1.serializers import FileUploadSerializer, NoIDFileUploadSerializer
|
||||
from shop.models import (
|
||||
Product,
|
||||
ProductPrice,
|
||||
@@ -64,6 +64,7 @@ class ProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = (
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"stock",
|
||||
@@ -77,16 +78,19 @@ class ProductSerializer(serializers.ModelSerializer):
|
||||
class ListProductSerializer(serializers.ModelSerializer):
|
||||
price = ProductPriceSerializer()
|
||||
tags = TagSerializer(many=True)
|
||||
images = NoIDFileUploadSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = (
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"stock",
|
||||
"is_digital_asset",
|
||||
"price",
|
||||
"tags",
|
||||
"images",
|
||||
)
|
||||
|
||||
|
||||
@@ -106,6 +110,11 @@ class CreateProductSerializer(serializers.ModelSerializer):
|
||||
is_digital_asset=validated_data.get("is_digital_asset"),
|
||||
url=validated_data.get("url"),
|
||||
)
|
||||
|
||||
tags = validated_data.get('tags')
|
||||
for tag in tags:
|
||||
instance.tags.add(tag)
|
||||
|
||||
ProductPrice.objects.create(
|
||||
product=instance,
|
||||
date=timezone.now(),
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 5.0.6 on 2024-05-17 00:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("files", "0001_initial"),
|
||||
("shop", "0005_tag_alter_product_images_product_tags"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="product",
|
||||
options={
|
||||
"ordering": ("id",),
|
||||
"verbose_name": "Producto",
|
||||
"verbose_name_plural": "Productos",
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="productbatch",
|
||||
options={
|
||||
"verbose_name": "Remesa de producto",
|
||||
"verbose_name_plural": "Remesas de productos",
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="tag",
|
||||
options={"verbose_name": "Etiqueta", "verbose_name_plural": "Etiquetas"},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="product",
|
||||
name="images",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, to="files.fileupload", verbose_name="Imágenes"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="product",
|
||||
name="tags",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, to="shop.tag", verbose_name="Etiquetas"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -53,6 +53,7 @@ class Product(models.Model):
|
||||
class Meta:
|
||||
verbose_name = _("Producto")
|
||||
verbose_name_plural = _("Productos")
|
||||
ordering = ('id', )
|
||||
|
||||
|
||||
class ProductPrice(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user