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
- [Answered ]-Boolean Comparison in Django Queryset?
- [Answered ]-Store two types of value in single Django model field
- [Answered ]-Django ManyToMany Query OR Issue
Source:stackexchange.com