Fakultas Ilmu Komputer UI

Commit ce19f188 authored by Reka Paska Enda's avatar Reka Paska Enda
Browse files

[REFACTOR] Memperbaiki bug Gambar produk pada halaman detail produk tidak terlihat

parent 556789f3
Pipeline #66175 passed with stages
in 8 minutes and 26 seconds
......@@ -626,6 +626,11 @@ class ProductList(generics.ListCreateAPIView):
def post(self, request, _format=None):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
validated_image = None
try:
validated_image = serializer.validated_data['image']
except KeyError:
pass
product = models.Product.objects.create(
name=serializer.validated_data['name'],
description=serializer.validated_data['description'],
......@@ -633,7 +638,8 @@ class ProductList(generics.ListCreateAPIView):
stock=serializer.validated_data['stock'],
modal=serializer.validated_data['modal'],
subcategory=models.Subcategory.objects.get(name=serializer.validated_data['subcategory']),
total_profit=0
total_profit=0,
image=validated_image
)
product.profit= (product.price - product.modal)
product.save()
......@@ -643,6 +649,7 @@ class ProductList(generics.ListCreateAPIView):
)
class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
permission_classes = [
api_permissions.IsAdminUserOrReadOnly,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment