Is there a way to augment django QuerySets with extra attributes?

前端 未结 5 1225
陌清茗
陌清茗 2021-01-14 19:06

I\'m trying to add some extra attributes to the elements of a QuerySet so I can use the extra information in templates, instead of hitting the database multiple times. Let m

5条回答
  •  [愿得一人]
    2021-01-14 19:48

    I would assume calling .reverse on a queryset s what is causing your issues. try this:

    books = Book.objects.filter(author__id=1)
    books_set = []
    for book in books:
        book.price = 2
        books_set.append(book)
    
    reverse = books_set.reverse()
    

提交回复
热议问题