gestioCOF/journaldecaisse/views.py
2020-02-18 22:02:46 +01:00

44 lines
1.3 KiB
Python

from django.http import HttpResponse
from .models import JournalEntry, Produit
from django.shortcuts import render
from django.http import JsonResponse
def index(request):
entry_list = JournalEntry.objects.order_by('entry_date')
context = {'entry_list': entry_list}
return render(request, 'journaldecaisse/index.html', context)
def vente(request):
product_list = Produit.objects.all().values_list()
products = []
for elem in product_list:
products.append(elem[1])
products = list(set(products))
context = {"product_list" : products}
return render(request, 'journaldecaisse/vente.html', context)
def iterate_options(request):
options_selected = request.GET.get('option', None)
options_selected = options_selected.split(":")
print(options_selected)
field = str(Produit._meta.get_fields()[int(options_selected[2])+3]).split(".")[-1]
print(field)
elems = Produit.objects.filter(**{options_selected[0]: options_selected[1]})
elems = elems.values_list()
options = []
for elem in elems:
options.append(elem[int(options_selected[2])+2])
options = list(set(options))
data = {
'options': options,
'options_int': int(options_selected[2])+2,
'field': field
}
return JsonResponse(data)