python - Select a specific object from a queryset django -
is there way select specific object found in results of queryset selecting item in array.
in arrays, can select specific item based on position:
arrayname = {55, 33, 34, 23} arrayname[2] result = 34
i want accomplish same thing queryset results
users in database = {steve, chris, jame, cole, casper, courtney} query filter names start c result = {chris, cole, casper, courtney}
after results, want select casper results... there way array.
something results[2]
update
so have part of view working specify specific record.
my other question see if possible same thing in html tempalte file... here have in view , html file. there way same thing ht ehtml file...
view.py
i=0 form in formset: cd = form.cleaned_data currentamount = cd['amount'] currentdescription = cd['description'] print(currentamount) print(currentdescription) currenttrans = transactions[i] currenttrans.amount = currentamount currenttrans.description = currentdescription currenttrans.save() print(currenttrans) = + 1
html
<form action="." method="post"> {% csrf_token %} {{ splitformset.management_form }} {% form in splitformset %} {{ form.as_p }} {% endfor %} <p>tax: <input type="text" name="tax" value=""></p> <p>tip: <input type="text" name="tip" value=""></p> <input type="submit" name="submit" value="submit"> </form>
i tried game me error becuase 'i' not tag
<form action="." method="post"> {% csrf_token %} {{ splitformset.management_form }} {% = 0 %} {% form in splitformset %} {{ transactions[i] }} {{ form.as_p }} {% = + 1 %} {% endfor %} <p>tax: <input type="text" name="tax" value=""></p> <p>tip: <input type="text" name="tip" value=""></p> <input type="submit" name="submit" value="submit"> </form>
names=model.objects.filter(name__istartswith='c') print(names[2])
in place of name have put field name of model
Comments
Post a Comment