python - Looping through multiple variables in view -


views.py

counter = 0     house in model...          if house.name = house.selected              counter++          else:             house.correct 

assumption: correct charfield within house model, looping through multiple houses else condition can entered multiple times.. upon completion end multiple house.corrects

prior loop suggestions on type of variables define store values i.e. list = [] when else statement entered can list = house.correct @ end have list potentially multiple character values... way can pass list through use in context.

is approach okay or doing poorly ? sorry lack of information give can understand i'm getting at. i'm struggling understand how can grab house.correct values , put them in 1 data type can pass them through context using variable see list of characters.

this can better implemented using django orm:

from django.db.models import f  ... incorrect_list = house.objects.exclude(name=f('selected')).values('correct') 

the f expression here allows compare model field field in same row , .values() method allow return list values of selected columns instead of queryset.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -