Pagination code:
try:
page = paginator.page(page_number)
print(page.object_list)
So the following output is the result of print(page.object_list) for my pagination:
<QuerySet [<Comment: I can't believe it's happeinig>, <Comment: Just trying to fill up the comments>, <Comment: Another one!>, <Comment: Evenmore noe>, <Comment: Something>, <Comment: Lol>, <Comment: Are comments showing up?>, <Comment: Great for the economy.>, <Comment: honestly>, <Comment: Even though the the onlyEven though the only one to udnertstnaf!>]>
<QuerySet [<Comment: Yeah it's crazy how fast aswell. It's very awesome how it's doing atm. >]>
<QuerySet []>
<QuerySet [<Comment: Sure>, <Comment: No worries>]>
<QuerySet []>
<QuerySet []>
<QuerySet [<Comment: attempt 2!>]>
<QuerySet [<Comment: Attempt 3!>]>
<QuerySet []>
<QuerySet [<Comment: 12>]>
<QuerySet []>
<QuerySet [<Comment: Somewhere?>]>
<QuerySet []>
<QuerySet [<Comment: lol>]>
<QuerySet []>
<QuerySet [<Comment: 12>]>
<QuerySet []>
As you can see I have empty querysets, and these are causing errors in my code. I therefore would like to iterate over these querysets and spot the empty ones. I tried to add this for loop:
for i in page.object_list:
if len(i) < 0:
but I get an error:
TypeError at /news/11/
object of type 'Comment' has no len()
Any help appreciated.
Trying to delete the a queryset if it is empty:
try:
page = paginator.page(page_number)
if page.object_list:
pass
else:
page.delete()
Error:
AttributeError at /news/11/
'CustomPage' object has no attribute 'delete'