Hi Lucas,
you're welcome. Great that you got it working.
hendrik
On 06/06/2012 03:26 AM, Lucas Aride Moulin wrote:
Sorry about the flood but I made it. I removed the "request.POST" of
the "else", and it worked.
Thank you Hendrik.
Problem solved
2012/6/5 Lucas Aride Moulin <[email protected]
<mailto:[email protected]>>
I'm sorry, the error was caused because I forgot to dedent the
"else". But it still not showing the current information on the
form. (it's working fine)
2012/6/5 Lucas Aride Moulin <[email protected]
<mailto:[email protected]>>
Hi Hendrik,
I did what you said but I got an error because the variable
"novo" is referenced before it's assignment.
My html of this view is:
<form method='post'> {% csrf_token %}
{{ novo.as_p }}
<input type="submit" value="Editar" />
</form>
2012/6/5 Hendrik Speidel <[email protected]
<mailto:[email protected]>>
Hi Lucas,
Try moving the first novo=... Right after if request.method
Then dedent the else and the line following it (the second
novo)
Then remove request.POST from the second novo
Explanation:
If the request method is not POST this will instanciate an
unbound form that loads the data from the instance.
If the request method is POST the form is populated using
the POST data. If it is valid the instance is saved. If it
is not valid django will set the errors on the form
Good luck!
Hendrik
----- Reply message -----
Von: "Lucas Aride Moulin" <[email protected]
<mailto:[email protected]>>
An: <[email protected]
<mailto:[email protected]>>
Betreff: How to edit form filling it with actual data
Datum: Di., Jun. 5, 2012 23:07
I have a function that creates a form, loading the info
that already exists
in the DB, but I want it to fill the form with the info
loaded. I found an
article on djangoproject teaching how to do this, but it
won't work with me.
At novo = disciplinaForm(request.POST, instance=atual),
if I remove the
"request.POST" it loads the info, but don't save. And with
"request.POST"
it do
The function:
def edit_disciplina(request, disciplina_id):
atual = disciplina.objects.get(pk=disciplina_id)
novo = disciplinaForm(request.POST, instance=atual)
if request.method == 'POST':
if novo.is_valid():
novo.save()
return HttpResponseRedirect('/disciplinas/success/')
else:
novo = disciplinaForm(request.POST, instance=atual)
return
render_to_response('/home/zephir/Template/disciplinas/edit_disciplina.html',
{'novo': novo}, context_instance=RequestContext(request))
--
Lucas Aride Moulin,
[email protected] <mailto:[email protected]>
--
You received this message because you are subscribed to
the Google Groups "Django users" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:django-users%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to
the Google Groups "Django users" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:django-users%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
Lucas Aride Moulin,
[email protected] <mailto:[email protected]>
--
Lucas Aride Moulin,
[email protected] <mailto:[email protected]>
--
Lucas Aride Moulin,
[email protected] <mailto:[email protected]>
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.