Feat: enviando las categorias en la lista de productos.
This commit is contained in:
@@ -2,7 +2,7 @@ from django.shortcuts import render
|
||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.template import loader
|
||||
|
||||
from .models import Sale, Product
|
||||
from .models import Sale, Product, ProductCategory
|
||||
from .forms import ImportProductsForm
|
||||
|
||||
import csv
|
||||
@@ -32,7 +32,7 @@ def products(request):
|
||||
"name": product.name,
|
||||
"price_list": product.price,
|
||||
"uom": product.measuring_unit,
|
||||
"category": ""#.join('&', [c for c in product.categories])
|
||||
"categories": [c.name for c in product.categories.all()]
|
||||
}
|
||||
rproducts.append(rproduct)
|
||||
|
||||
@@ -64,3 +64,10 @@ def handle_import_products_file(csv_file):
|
||||
product.price = row['precio']
|
||||
product.measuring_unit = row['unidad']
|
||||
product.save()
|
||||
|
||||
categories = [n.strip for n in row["categorias"].split("&")]
|
||||
for category in categories:
|
||||
category_model, _ = ProductCategory.objects.get_or_create(
|
||||
name=category
|
||||
)
|
||||
product.categories.add(category_model)
|
||||
|
||||
Reference in New Issue
Block a user