A
A
Ayom Khabibov2021-04-21 15:38:47
Django
Ayom Khabibov, 2021-04-21 15:38:47

How to change data in multiple tables at the same time django rest framework?

I'm trying to change the data from the front and send it to the save on the db. Now how do I keep the change in the vase.
My serializer

class ProductSerializer(serializers.HyperlinkedModelSerializer):
    category_id = CategorySerializer()
    county_id = CountriesSerializer()
    addin_id = AddinSerializer()
    nomenclatures_id = NomenclaterusSerializer()

    class Meta:
        model = Product
        fields = ['name', 'marketplace_product_id', 'offer_id', 'old_price', 'imtId', 'price', 'short_description', 'long_description', 'category_id', 'county_id', 'addin_id', 'nomenclatures_id', 'createAt', 'timestamps', ]


class ProductImageSerializer(serializers.HyperlinkedModelSerializer):
    product_id = ProductSerializer()

    class Meta:
        model = ProductImage
        fields = ['product_id', 'url']


class MarketPlacesSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = MarketPlaces
        fields = ['title',]


class ProductMarketplacesSerializer(serializers.HyperlinkedModelSerializer):
    product_id = ProductSerializer()
    marketplace_name = MarketPlacesSerializer()

    class Meta:
        model = ProductMarketplaces
        fields = ['product_id', 'marketplace_name', 'value']


My view to send the product to the front
class ProductView(ObjectMultipleModelAPIView):

    querylist = [
        {
            'queryset': ProductMarketplaces.objects.all(),
            'serializer_class': ProductMarketplacesSerializer,
            'label': 'product',
        },
        {
            'queryset': ProductImage.objects.all(),
            'serializer_class': ProductImageSerializer,
            'label': 'images',
        }

    ]
    pagination_class = LimitPagination


What I get from the front
[
            {
                "product_id": {
                    "id": 1001,
                    "name": "Куртки",
                    "marketplace_product_id": "335149ec-bd3a-5543-a183-f4d14361d9b9",
                    "offer_id": "",
                    "old_price": 0.0,
                    "imtId": 14102290,
                    "price": 0.0,
                    "short_description": "",
                    "long_description": "",
                    "category_id": {
                        "market_category_id": 1,
                        "name": "Куртки",
                        "parent_category_id": {
                            "name": "Одежда",
                            "description": ""
                        }
                    },
                    "county_id": {
                        "id": 1,
                        "name": "Бангладеш"
                    },
                    "addin_id": {
                        "brand_id": {
                            "id": 2,
                            "brand": "RIFLE"
                        },
                        "gender_id": {
                            "gender": "Женский"
                        },
                        "name_id": {
                            "name": "Куртка"
                        },
                        "description": "",
                        "tnved": "6211331000",
                        "compound_id": {
                            "value": "нейлон",
                            "count": 25,
                            "units": "%"
                        },
                        "complact": "куртка",
                        "width_on": null,
                        "taking_things": null,
                        "model_shoes": null,
                        "fastener_type": null,
                        "material_texture": null,
                        "pockets_type": null
                    },
                    "nomenclatures_id": {
                        "nomenclature_marketplace_id": "b0a17efc-9829-47a4-8790-7585f284d023",
                        "nmid": 18994895,
                        "vendore_code": "RJ3163-77600-64X/col",
                        "variabls_id": {
                            "variations_market_id": "26453fb2-7518-43ca-b21c-80fa2a5b42db",
                            "chrid": 51046376,
                            "barcode": "[]",
                            "variations_addin_id": {
                                "size": "",
                                "growth_size": "",
                                "difference_price": "3236",
                                "waistband": null,
                                "length": null,
                                "russian_size": null
                            }
                        },
                        "nomenclature_addin": {
                            "collection": "Базовая коллекция",
                            "color": ""
                        }
                    },
                    "createAt": "2021-04-13T11:44:33.073367Z",
                    "timestamps": "2021-04-13T11:44:33.073464Z"
                },
                "marketplace_name": {
                    "title": "Wildberries"
                },
                "value": "335149ec-bd3a-5543-a183-f4d14361d9b9"
            }]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question