On 3/5/06, Jeremy Jones <[EMAIL PROTECTED]> wrote:
>
> Is it bad form to put a database object in a session variable?  It
> really just feels wrong, but it works.  Typically, I would just put the
> object's ID in a session variable and retrieve the object when I next
> needed it, but I accidentally forgot to do
> ``request.session["this_thing"] = obj.id`` and instead did
> ``request.session["this_thing"] = obj`` and I surprisingly found
> myself with access to the object itself rather than just the ID of the
> object.  Anyway, I was wondering if it works by design and is thus
> acceptable, or if it works by accident and should be avoided.

http://www.djangoproject.com/documentation/sessions/#technical-details

You *can* do it, but I wouldn't recommend it. I can easily imagine a
situation where the version you have sotred in the session, and the
version stored in the database could get out of sync. Storing obj.id
and re-retreiving the object will probably be much safer. If you need
to avoid the extra database hit, use the caching framework. :)

Joseph

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to