On Wed, Dec 30, 2009 at 02:31, Koobz <[email protected]> wrote: > Hi Folks, > > This is my problem: I want a notion of preferences for anonymous users > and registered users. > > Preferences can be things like "saved searches", "favorite > restaurant", or a personalized portal configuration for the home page. > > The immediate solution is to store a pickled preference object inside > of the session. This works great for anonymous users, but for > registered users there is an additional expectation of persistence: If > I log in from a different computer I expect to see my preferences > restored - meaning the preferences in this case should be attached to > the user. A cookie with a long expiry doesn't work when I log in from > another computer. > > I'm almost certain there's some de-facto solution out there. I'm > trying to keep things as transparent as possible so I don't have to > juggle anonymous visitors and registered users through different > preference mechanisms. Some pseudocode: > > if anonymous: > fetch_preferences_from_session() # Returns AnonymousPreference > object > if registered: > fetch_preferences_from_user() # Returns UserPreference object > > The UserPreference object and AnonymousPreference object can then > expose a common api and blackbox their storage details (the anonymous > one will simply write to the session, the UserPreference will store to > database to some kind of preference table with a 1-1 Foreign key to > the user). > > But I figure I'm going to facepalm myself when it turns out Django > already solves this problem (like it does for most other "core" > problems ;) > > Hello,
Perhaps the "user profile" concept of django is what you are looking for: http://www.djangobook.com/en/1.0/chapter12/#cn222 Cheers, Adrian Maier -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

