class Book(models.Model):
author = models.ForeignKey(User)
name = models.CharField(max_length=100)
def view(request):
book = Book.objects.get(pk=1)
request.session['selected_book'] = book
Is it a good practice to store Objects in Session instead of their id ?
Will it be "picklable" enough to be used in templates for example ?
<div>{{ request.session.book.author.name }}</div>
This seems like a bad idea. Apart from anything else, if you store an object in the session, it won't change if/when the database version does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With