Is there a way to augment django QuerySets with extra attributes?
问题 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 me illustrate by example, assuming we have Books with ForeignKeys to Authors. >>> books = Book.objects.filter(author__id=1) >>> for book in books: ... book.price = 2 # "price" is not defined in the Book model >>> # Check I can get back the extra information (this works in templates too): >>> books[0].price 2 >>> # but it's