diff options
Diffstat (limited to 'docs/topics/forms/modelforms.txt')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 882478fc2a..67b8ba510d 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -954,7 +954,7 @@ Model formsets are very similar to formsets. Let's say we want to present a formset to edit ``Author`` model instances:: from django.forms import modelformset_factory - from django.shortcuts import render_to_response + from django.shortcuts import render from myapp.models import Author def manage_authors(request): @@ -966,9 +966,7 @@ formset to edit ``Author`` model instances:: # do something. else: formset = AuthorFormSet() - return render_to_response("manage_authors.html", { - "formset": formset, - }) + return render(request, 'manage_authors.html', {'formset': formset}) As you can see, the view logic of a model formset isn't drastically different than that of a "normal" formset. The only difference is that we call @@ -1022,7 +1020,7 @@ As stated earlier, you can override the default queryset used by the model formset:: from django.forms import modelformset_factory - from django.shortcuts import render_to_response + from django.shortcuts import render from myapp.models import Author def manage_authors(request): @@ -1035,9 +1033,7 @@ formset:: # Do something. else: formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O')) - return render_to_response("manage_authors.html", { - "formset": formset, - }) + return render(request, 'manage_authors.html", {'formset': formset}) Note that we pass the ``queryset`` argument in both the ``POST`` and ``GET`` cases in this example. @@ -1213,9 +1209,7 @@ of a model. Here's how you can do that:: return HttpResponseRedirect(author.get_absolute_url()) else: formset = BookInlineFormSet(instance=author) - return render_to_response("manage_books.html", { - "formset": formset, - }) + return render(request, 'manage_books.html', {'formset': formset}) Notice how we pass ``instance`` in both the ``POST`` and ``GET`` cases. |
