gestioCOF/journaldecaisse/views.py

45 lines
1.3 KiB
Python
Raw Normal View History

2020-02-16 18:37:16 +01:00
from django.http import HttpResponse
2020-02-18 18:25:54 +01:00
from .models import JournalEntry, Produit
2020-02-17 11:40:58 +01:00
from django.shortcuts import render
2020-02-18 18:25:54 +01:00
from django.http import JsonResponse
2020-02-16 18:37:16 +01:00
def index(request):
2020-02-17 11:40:58 +01:00
entry_list = JournalEntry.objects.order_by('entry_date')
context = {'entry_list': entry_list}
2020-02-18 18:25:54 +01:00
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):
2020-02-18 22:02:46 +01:00
2020-02-18 18:25:54 +01:00
options_selected = request.GET.get('option', None)
options_selected = options_selected.split(":")
print(options_selected)
2020-02-18 22:02:46 +01:00
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))
2020-02-18 18:25:54 +01:00
data = {
2020-02-18 22:02:46 +01:00
'options': options,
'options_int': int(options_selected[2])+2,
'field': field
2020-02-18 18:25:54 +01:00
}
return JsonResponse(data)