[Answered ]-Django Query in a loop fails for no good reason

1👍

The range function will give you a zero based list of numbers up to and excluding msgs. I guess there is no Tip with week_number=0.

1👍

Also, to limit the number of queries you could do this:

for tip in Tip.objects.filter(week_number__lt=msgs):
    #do something

or, if you want specific weeks:

weeks=(1,3,5)
for tip in Tip.objects.filter(week_number__in=weeks):
    #do something
👤tback

Leave a comment