Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to set a variable on session, when a user login happens. How can I do this?

if request.user.is_authenticated():
profile = request.user.get_profile()
request.session['idempresa'] = profile.idempresa

My other question is in a form:

class PedidoItensForm(ModelForm):
class Meta:
    model = ItensPedido

def __init__(self, *args, **kwargs):
    profile = kwargs.pop('vUserProfile', None)
    super(PedidoItensForm, self).__init__(*args, **kwargs)

How can I get the "idempresa" value of session, to use in my queryset?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
230 views
Welcome To Ask or Share your Answers For Others

1 Answer

For setting session variable:

request.session['idempresa'] = profile.idempresa

For getting session Data:

if 'idempresa' in request.session:
    idempresa = request.session['idempresa']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...