From d162b0bcd8367cc2ddf1ccd613a80a2e82c3b262 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 22 Dec 2015 10:21:24 -0500 Subject: [1.9.x] Fixed #25969 -- Replaced render_to_response() with render() in docs examples. Backport of 4d83b0163e15f8352fd17fa121e929842ff2b686 from master --- docs/topics/forms/modelforms.txt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'docs/topics/forms/modelforms.txt') 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. -- cgit v1.3