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