mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
criado endpoint para gerar um json do cardapio
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,5 +8,7 @@ urlpatterns = [
|
|||||||
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
|
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
|
||||||
path('searchProduct', views.searchProduct, name='searchProduct'),
|
path('searchProduct', views.searchProduct, name='searchProduct'),
|
||||||
path('editProduct/<int:productId>/', views.editProduct, name='editProduct'),
|
path('editProduct/<int:productId>/', views.editProduct, name='editProduct'),
|
||||||
|
path('createJson', views.createJson, name='createJson'),
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import json
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
from categories.models import Categories
|
from categories.models import Categories
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
@@ -60,3 +63,26 @@ def editProduct(request, productId):
|
|||||||
product = ''
|
product = ''
|
||||||
products = Product.objects.filter(name__icontains=product)
|
products = Product.objects.filter(name__icontains=product)
|
||||||
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||||
|
|
||||||
|
def createJson(request):
|
||||||
|
products = Product.objects.filter(active=True).exclude(
|
||||||
|
category__name__in=['insumos', 'Cervejas', 'pratos']
|
||||||
|
)
|
||||||
|
product_list = []
|
||||||
|
for product in products:
|
||||||
|
product_data = {
|
||||||
|
"id": product.id,
|
||||||
|
"name": product.name,
|
||||||
|
"description": product.description or "",
|
||||||
|
"price": float(product.price),
|
||||||
|
"category": product.category.name if product.category else "",
|
||||||
|
"image": str(product.image) if product.image else f"https://placehold.co/400x250/efc7b8/49291c?text={product.name.replace(' ', '+')}"
|
||||||
|
}
|
||||||
|
product_list.append(product_data)
|
||||||
|
|
||||||
|
# Retorna como JSON em texto simples
|
||||||
|
return HttpResponse(
|
||||||
|
json.dumps(product_list, indent=4, ensure_ascii=False),
|
||||||
|
content_type="application/json; charset=utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user