mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Improved example of using a custom queryset in Model formsets docs.
This commit is contained in:
		| @@ -1069,16 +1069,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`` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user