title: How to set and get session variable in django?
body: <p>I need to set a variable on session, when a user login happens. How can I do this?</p>
  <pre><code>if request.user.is_authenticated():
      profile = request.user.get_profile()
      request.session['idempresa'] = profile.idempresa
  </code></pre>
  <p>My other question is in a form:</p>
  <pre><code>class PedidoItensForm(ModelForm):
      class Meta:
          model = ItensPedido
  
      def __init__(self, *args, **kwargs):
          profile = kwargs.pop('vUserProfile', None)
          super(PedidoItensForm, self).__init__(*args, **kwargs)
  </code></pre>
  <p>How can I get the &quot;idempresa&quot; value of session, to use in my queryset?</p>