neurix
neurix

Reputation: 4316

Django: Save cleaned_data in a session effectively

In one of my forms, I am processing the form data and save it in a session variable.

So when I run

if locationForm.is_valid():

I execute

request.session['streetNumber'] = locationForm.cleaned_data['streetNumber']
request.session['postalCode'] = locationForm.cleaned_data['postalCode']
request.session['state'] = locationForm.cleaned_data['state']
request.session['country'] = locationForm.cleaned_data['country']

But this seems very inefficient. I have tried

request.session = locationForm.cleaned_data

but it does not seem to work.

Upvotes: 4

Views: 1782

Answers (1)

czarchaic
czarchaic

Reputation: 6338

what about

for k, v in locationform.cleaned_data.iteritems():
  session[ k ] = v

Upvotes: 3

Related Questions