I tried the following but it fails in flames with "http response
required..." I've followed the documentation - am I called the
function correctly by a url with "/mymodel_addedit" Can someone help ?
urls.py
r'^mymodel/addedit/$', 'myproject.myapp.views.mymodel_addedit'),
views.py
def mymodel_addedit(request, id=None):
if id is None:
MyModelForm = forms.models.form_for_model(MyModel)
else:
mymodel = MyModel.objects.get(id=id)
MyModelForm = forms.models.form_for_instance(mymodel)
if request.method == 'POST':
form = MyModelForm(request.POST)
if form.is_valid():
mymodel = form.save(commit=False)
mymodel.save()
return HttpResponseRedirect("/")
else:
form = MyModelForm()
return render_to_response('mymodel_addedit.html', {'form': form})
/templates/mymodel_addedit.html
{% extends "base.html" %}
{% block content %}
<form action="." method="post">
<table class="form">
{{ form }}
</table>
<input type="submit" value="Submit" />
</form>
{% endblock %}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---