Fakultas Ilmu Komputer UI

Commit 11a91da4 authored by Azhar Difa Arnanda's avatar Azhar Difa Arnanda 💬
Browse files

Merge branch 'reka/4/Gambar_produk_pada_halaman_detail_produk_tidak_terlihat' into 'dev'

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

See merge request !7
parents 7446f6f1 ce19f188
Pipeline #68050 passed with stages
in 5 minutes and 15 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