Django modelForm changes aspect when is submitted

Ridohomfodo

New Member
I'm trying to create a web using django where a form is prompted to the user, that can fill some values of it and submit them. Then, the python program will fill the rest and show the form filled by the user, with also the fields filled by the server. I am using modelForms, as I want a complete matching between my model and my form.For several reasons I have come to do it using the following code, but I don't know why after submitting the form, the fields don't appear as CharFields anymore, but as something similar to 'html labels', and are not editable anymore. The code is a very simplified version of mine, where there is only one field, filled by the user.views.py:\[code\]def manage_printers(request): p = PrinterForm(request.POST or None) if request.method == 'POST': if p.is_valid(): f = p.save(commit=False) f.name = request.POST.get('name') f.save() return render_to_response('web.html', {'printer': f}) else: return HttpResponse("form not valid") return render_to_response('web.html', {'printer': p}, ) \[/code\]models.py:\[code\]class Printer(models.Model): name = models.CharField(max_length=200, default=' ') def __unicode__(self): return self.nameclass PrinterForm(ModelForm): class Meta: model = Printer\[/code\]web.html:\[code\]<form action="/useriface/" method="post"> <p>Name: {{ printer.name }}</p></form>\[/code\]
 
Back
Top