Spaces:
Sleeping
Sleeping
gamingflexer
commited on
Commit
·
07058d2
1
Parent(s):
23f8016
Update models.py and views.py
Browse files- src/app/api/models.py +2 -2
- src/app/api/views.py +11 -5
src/app/api/models.py
CHANGED
@@ -9,10 +9,10 @@ class Product(models.Model):
|
|
9 |
sub_brand = models.CharField(max_length=100, blank=True, null=True)
|
10 |
manufactured_by = models.CharField(max_length=200, null=True)
|
11 |
product_name = models.CharField(max_length=200, null=True)
|
12 |
-
weight = models.
|
13 |
variant = models.CharField(max_length=100, blank=True, null=True)
|
14 |
net_content = models.CharField(max_length=100, blank=True, null=True)
|
15 |
-
price = models.
|
16 |
parent_category = models.CharField(max_length=100, null=True)
|
17 |
child_category = models.CharField(max_length=100, null=True)
|
18 |
sub_child_category = models.CharField(max_length=100, blank=True, null=True)
|
|
|
9 |
sub_brand = models.CharField(max_length=100, blank=True, null=True)
|
10 |
manufactured_by = models.CharField(max_length=200, null=True)
|
11 |
product_name = models.CharField(max_length=200, null=True)
|
12 |
+
weight = models.CharField(null=True,max_length=200)
|
13 |
variant = models.CharField(max_length=100, blank=True, null=True)
|
14 |
net_content = models.CharField(max_length=100, blank=True, null=True)
|
15 |
+
price = models.CharField(max_length=100, blank=True, null=True)
|
16 |
parent_category = models.CharField(max_length=100, null=True)
|
17 |
child_category = models.CharField(max_length=100, null=True)
|
18 |
sub_child_category = models.CharField(max_length=100, blank=True, null=True)
|
src/app/api/views.py
CHANGED
@@ -81,6 +81,8 @@ def catalouge_page(request):
|
|
81 |
def upload_image_and_audio(request):
|
82 |
if request.method == 'POST' and request.FILES.getlist('images'):
|
83 |
images = request.FILES.getlist('images')
|
|
|
|
|
84 |
for image in images:
|
85 |
# Save the image locally in the static directory
|
86 |
image_name = image.name
|
@@ -88,18 +90,22 @@ def upload_image_and_audio(request):
|
|
88 |
with open(image_path, 'wb') as f:
|
89 |
for chunk in image.chunks():
|
90 |
f.write(chunk)
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
static_img_path = "http://34.122.223.224:9002/media/images/" + image_name
|
94 |
product_data = {
|
95 |
'brand': input_data.get('brand',None),
|
96 |
'mrp': input_data.get('mrp',None),
|
97 |
-
'quantity':
|
98 |
'parent_category': input_data.get('parent_category',None),
|
99 |
'manufactured_by': input_data.get('manufactured_by', ''),
|
100 |
'product_name': input_data.get('type_of_product',None),
|
101 |
-
'images_paths':
|
102 |
-
'description': input_data.get('description',None)
|
|
|
|
|
103 |
}
|
104 |
|
105 |
# Create a new Product instance and save to database
|
|
|
81 |
def upload_image_and_audio(request):
|
82 |
if request.method == 'POST' and request.FILES.getlist('images'):
|
83 |
images = request.FILES.getlist('images')
|
84 |
+
image_path_list = []
|
85 |
+
static_img_path_list = []
|
86 |
for image in images:
|
87 |
# Save the image locally in the static directory
|
88 |
image_name = image.name
|
|
|
90 |
with open(image_path, 'wb') as f:
|
91 |
for chunk in image.chunks():
|
92 |
f.write(chunk)
|
93 |
+
image_path_list.append(image_path)
|
94 |
+
static_img_path_list.append(("http://34.122.223.224:9002/media/images/" + image_name))
|
95 |
+
print('Image saved at:', image_path_list)
|
96 |
+
input_data = get_details(image_path_list)
|
97 |
static_img_path = "http://34.122.223.224:9002/media/images/" + image_name
|
98 |
product_data = {
|
99 |
'brand': input_data.get('brand',None),
|
100 |
'mrp': input_data.get('mrp',None),
|
101 |
+
'quantity': 1,
|
102 |
'parent_category': input_data.get('parent_category',None),
|
103 |
'manufactured_by': input_data.get('manufactured_by', ''),
|
104 |
'product_name': input_data.get('type_of_product',None),
|
105 |
+
'images_paths': ",".join(static_img_path_list), # Save the image paths as a comma-separated string
|
106 |
+
'description': input_data.get('description',None) ,
|
107 |
+
'price' : input_data.get('price',None),
|
108 |
+
'weight': input_data.get('weight',None),
|
109 |
}
|
110 |
|
111 |
# Create a new Product instance and save to database
|