diff options
| author | Mike Lissner <mike@free.law> | 2022-02-02 21:58:14 -0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-03 06:58:51 +0100 |
| commit | 62fe7e08d69eca8d8d1aa62855f2bc375d35b8f1 (patch) | |
| tree | 5efaf01111cbd5b9cad9075aec5fe82c94173942 | |
| parent | efe72cf128a37cd11ba28fde6ed82e73be4f90d2 (diff) | |
[4.0.x] Improved example of using a custom queryset in Model formsets docs.
Backport of e459b0f5a0b2bfbc2ac45b3e7f21047ec9e4f345 from main
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index cf79fc69c4..923690eb9c 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -1050,16 +1050,17 @@ formset:: def manage_authors(request): AuthorFormSet = modelformset_factory(Author, fields=('name', 'title')) + queryset = Author.objects.filter(name__startswith='O') if request.method == "POST": formset = AuthorFormSet( request.POST, request.FILES, - queryset=Author.objects.filter(name__startswith='O'), + queryset=queryset, ) if formset.is_valid(): formset.save() # Do something. else: - formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O')) + formset = AuthorFormSet(queryset=queryset) return render(request, 'manage_authors.html', {'formset': formset}) Note that we pass the ``queryset`` argument in both the ``POST`` and ``GET`` |
