It is possible to do this some how:
class Login_vw(FormView):
form_class = Login_fr
success_url = '/success/'
template_name = 'login.html'
someVar_ses = self.request.session['someVar']
record_qr = MyModel.objects.filter(id=someVar_ses)
When I do that I get this:
NameError: name 'self' is not defined
But when I use it within a method like get_context_data it works right.
What I need is to use the record_qr var in different methods and don't repeat the code in each one.
Is there a way?
Edited to add this details:
What I'm trying to do is something like this:
class Login_vw(FormView):
form_class = Login_fr
success_url = '/success/'
template_name = 'login.html'
def get_context_data(self, **kwargs):
context = super(Login_vw, self).get_context_data(**kwargs)
idProspect_ses = self.request.session['idProspect']
Prospect_qr = PROSPECT.objects.filter(id=idProspect_ses).values('id', 'email', 'pwd')
context['email'] = Prospect_qr[0]['email']
return context
def form_valid(self, form):
formData = form.clean()
pwd_f = formData.get("password")
if pwd_f == Prospect_qr[0]['pwd']:
print "password correct"
else:
print "wrong password"
So, I tried do it with self like this, but I got an attribute error (object has no attribute Prospect_qr)
class Login_vw(FormView):
form_class = Login_fr
success_url = '/success/'
template_name = 'login.html'
def get_context_data(self, **kwargs):
context = super(Login_vw, self).get_context_data(**kwargs)
idProspect_ses = self.request.session['idProspect']
self.Prospect_qr = PROSPECT.objects.filter(id=idProspect_ses).values('id', 'email', 'pwd')
context['email'] = self.Prospect_qr[0]['email']
return context
def form_valid(self, form):
formData = form.clean()
pwd_f = formData.get("password")
if pwd_f == self.Prospect_qr[0]['pwd']:
print "password correct"
else:
print "wrong password"