I have the following form:
class SourceForm(forms.ModelForm):
class Meta:
model = Source
widgets = {
'category_re': forms.TextInput(),
'thumb_re': forms.TextInput(),
'movie_re': forms.TextInput()
}
def clean_url(self):
data = self.cleaned_data['url']
return helpers.url_fix(data)
and the following view:
def source_form(request, id):
source = get_object_or_404(Source, pk=id)
form = SourceForm(request.POST or None, instance=source)
if form.is_valid():
form.save()
return render_to_response('source/form.html', {'form': form, 'source': source},
context_instance=RequestContext(request))
And I have the problem. Cleaned value of url field don’t shown in the form. I see only old, not modified value, but then I try to add {{ form.cleaned_data }} in the template – it shows right value. Why it happened so? How can I fix it?
TIA!
It’s because your
formis using therequest.POSTdata and not thecleaned_data. Try reassigning yourformvariable after yoursave():