Django: How/Where to store a value for a session without unnecessary DB hits

Posted by GerardJP on Stack Overflow See other posts from Stack Overflow or by GerardJP
Published on 2010-04-07T21:28:38Z Indexed on 2010/04/07 21:33 UTC
Read the original article Hit count: 215

Hi all,

I have an extended userprofile with AUTH_PROFILE_MODULE (ref: http://tinyurl.com/yhracqq)

I would like to set a user.is_guru() method similar to user.is_active(). This would results for al views (or rather templates) to e.g. disable/enable certain user messages, displaying of widgets, etc. The boolean is stored in the extended user profile model, but I want to avoid hitting the DB for every view.

So the questions is .. Do I use a context_processor, a template tag, session_dict or what have you to, possible cached, store this info for the duration of the users visit.

Note: I dont have performance issues, so it's definitely filed under premature optimization. I just want to avoid generating extra work in the future :).

Any pointers are very welcome.

Thanx and greetz!

Gerard.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models