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): ...@@ -626,6 +626,11 @@ class ProductList(generics.ListCreateAPIView):
def post(self, request, _format=None): def post(self, request, _format=None):
serializer = self.get_serializer(data=request.data) serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
validated_image = None
try:
validated_image = serializer.validated_data['image']
except KeyError:
pass
product = models.Product.objects.create( product = models.Product.objects.create(
name=serializer.validated_data['name'], name=serializer.validated_data['name'],
description=serializer.validated_data['description'], description=serializer.validated_data['description'],
...@@ -633,7 +638,8 @@ class ProductList(generics.ListCreateAPIView): ...@@ -633,7 +638,8 @@ class ProductList(generics.ListCreateAPIView):
stock=serializer.validated_data['stock'], stock=serializer.validated_data['stock'],
modal=serializer.validated_data['modal'], modal=serializer.validated_data['modal'],
subcategory=models.Subcategory.objects.get(name=serializer.validated_data['subcategory']), 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.profit= (product.price - product.modal)
product.save() product.save()
...@@ -643,6 +649,7 @@ class ProductList(generics.ListCreateAPIView): ...@@ -643,6 +649,7 @@ class ProductList(generics.ListCreateAPIView):
) )
class ProductDetail(generics.RetrieveUpdateDestroyAPIView): class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
permission_classes = [ permission_classes = [
api_permissions.IsAdminUserOrReadOnly, 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