python - Where to store object information django? -
in django project need access object of user`s character(a model), where should store value of object ? since using in multiple views display content in template. should store in session, retrieve database every time or other alternative?
class character(models.model): user = models.onetoonefield(user, on_delete=models.cascade,primary_key=true) gold = models.integerfield(default=gold) points = models.integerfield(default = startpoints)
not sure means character
, but: if not session-based, permanent information(and believe is) need store in database able fetch when user log in. how store not matter - can dedicated table if need it(in case nice add user fk) or field in user
table.
then, if have session middleware , authentication middleware, able access user
object request object, need is: request.user.character
i hope helpful.
upd: way store data between requests in db or caching system(if have non-db cache or don't store session in db in faster instead - redis or memcache). adraid way.
for per-session data can use cookies in situation, think isn't case.
Comments
Post a Comment