[Answered ]-Why am I unable to assign a value to a form field on submit?

2👍

✅

You can try this instead:

# --- Replace this ---
# form.cleaned_data['nearbyzips1'] = zip_codes[1]
# print form.cleaned_data['nearbyzips1']
# profile = form.save()
# --- whith this ---
profile = form.save(commit=False)
profile.nearbyzips1 = zip_codes[1]
profile.save()

I really don’t like to place business logic into ModelForm.save, prefer to place all business logic into the view.

Leave a comment