Update Prodcut(model) quantity(attribute) from Stock(model) quantity(attribute) in API.

185 views
Skip to first unread message

yousuf

unread,
Aug 18, 2022, 10:00:31 AM8/18/22
to Django REST framework
2..PNGStock Model. This is the model for Stock which have foreign key of Product Model. From this model i want to update product quantity of Product Model.3..PNGStock Viewset. This is the viewset for displaying data.4..PNGThis is Stock Serializer where i had written logic for updating product quantity from stock model.5..PNGThis is the Product whose id is 2 and it has quantity of 5. Now i want this quantity to be updated when user add stock from Stock Model.6..PNGNow in Stock, i added 15 quantity. So Previously product has 5 quantity. SInce i added 15more quantity for Apple product. I want it to be added on Product Model also.7..PNGIn console, while printing i can see 5 that is previous quantity and 20 after adding stock.  But in Product API i cannot see that updated quantity. 1..PNGTHis is Product model.
I need help for updating Product quantity from Stock model.

Onjomba Felix

unread,
Aug 18, 2022, 3:28:51 PM8/18/22
to django-res...@googlegroups.com
At The Stock Serializer You Have Just Updated But you have not saved the changes can you check on that

On Thu, 18 Aug 2022 at 17:00, yousuf <sanjayb...@gmail.com> wrote:
2..PNGStock Model. This is the model for Stock which have foreign key of Product Model. From this model i want to update product quantity of Product Model.3..PNGStock Viewset. This is the viewset for displaying data.4..PNGThis is Stock Serializer where i had written logic for updating product quantity from stock model.5..PNGThis is the Product whose id is 2 and it has quantity of 5. Now i want this quantity to be updated when user add stock from Stock Model.6..PNGNow in Stock, i added 15 quantity. So Previously product has 5 quantity. SInce i added 15more quantity for Apple product. I want it to be added on Product Model also.7..PNGIn console, while printing i can see 5 that is previous quantity and 20 after adding stock.  But in Product API i cannot see that updated quantity. 1..PNGTHis is Product model.
I need help for updating Product quantity from Stock model.

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/92132b1b-f8e6-4ba9-a7a8-b2e2b3d6c644n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages