forked from DGNum/gestioCOF
Fetch list of products
This commit is contained in:
parent
5952ef1cbf
commit
eb5b459294
|
@ -4,19 +4,28 @@
|
||||||
{% block realcontent %}
|
{% block realcontent %}
|
||||||
<h2>Vente</h2>
|
<h2>Vente</h2>
|
||||||
|
|
||||||
|
<div id="lol">
|
||||||
{% for product in product_list %}
|
{% for product in product_list %}
|
||||||
<button id="button_option" value="Produit:{{ product }}">{{ product }}</button>
|
<button id="button_option" value="Produit:{{ product }}:1">{{ product }}</button>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
function addButton(elem, index, option, option_int){
|
||||||
|
|
||||||
|
var r = $('<button id="button_option" value="'+option+':'+elem+':'+option_int+'">'+ elem + '</button>');
|
||||||
|
$("#lol").append(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$(document).on("click", "#button_option", function () {
|
$(document).on("click", "#button_option", function () {
|
||||||
|
$(this).css('background', 'yellow');
|
||||||
|
$("[id=button_option]").prop("disabled", true);
|
||||||
var option_clicked = $(this).val();
|
var option_clicked = $(this).val();
|
||||||
console.log(option_clicked)
|
console.log(option_clicked);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'ajax/iterate_options/',
|
url: 'ajax/iterate_options/',
|
||||||
|
@ -25,8 +34,16 @@ $(document).ready(function() {
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
console.log(data);
|
||||||
|
var r = $('<br>');
|
||||||
|
$("#lol").append(r);
|
||||||
|
data.options.forEach(function (item, index) {
|
||||||
|
addButton(item, index, data.field, data.options_int)
|
||||||
|
});
|
||||||
|
if (data.options[0] === ""){
|
||||||
|
console.log("lol")
|
||||||
|
}
|
||||||
|
|
||||||
alert(data);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,14 +23,22 @@ def vente(request):
|
||||||
|
|
||||||
|
|
||||||
def iterate_options(request):
|
def iterate_options(request):
|
||||||
|
|
||||||
options_selected = request.GET.get('option', None)
|
options_selected = request.GET.get('option', None)
|
||||||
options_selected = options_selected.split(":")
|
options_selected = options_selected.split(":")
|
||||||
print(options_selected)
|
print(options_selected)
|
||||||
|
field = str(Produit._meta.get_fields()[int(options_selected[2])+3]).split(".")[-1]
|
||||||
test = Produit.objects.filter(**{ options_selected[0] : options_selected[1] })
|
print(field)
|
||||||
print(test)
|
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 = {
|
data = {
|
||||||
'is_taken': None
|
'options': options,
|
||||||
|
'options_int': int(options_selected[2])+2,
|
||||||
|
'field': field
|
||||||
}
|
}
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
Loading…
Reference in a new issue