Answer the question
In order to leave comments, you need to log in
Negative indexing is not supported. how to loop through and output the last 8 elements of a QuerySet list?
Good afternoon, I ran into a problem, I need to display the last 8 articles with the "Architecture" tag, but when I try to slice the list, I get Negative indexing is not supported.
tag_arch = TagPlaceModel.objects.get(name='Архитектура').placemodel_set.all()[:-8]
tag_arch = TagPlaceModel.objects.get(name='Архитектура').placemodel_set.all()[:-8]
a = list(tag_arch)[:-8]
Answer the question
In order to leave comments, you need to log in
in the model
class Meta:
verbose_name = 'Новость'
verbose_name_plural = 'Новости'
ordering = ['-id']
tag_arch = TagPlaceModel.objects.get(name='Архитектура').placemodel_set.all()[0:8]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question