Skip to content

Commit

Permalink
use extra
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sanders committed May 9, 2024
1 parent 1f7af0e commit 209e782
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions bulk_create_form/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

from .models import User

# todo:
# ✓ check if at least one new object
# ✓ validation inline?
# ✓ none qs


class BaseUserFormSet(BaseModelFormSet):
# modelformset_factory() unfortunately has no way to set queryset & prevent loading from the db
Expand All @@ -26,7 +21,8 @@ def bulk_create_users(request):
)

if request.method == "POST" and "add-row" in request.POST:
UserFormSet.min_num = int(request.POST["form-TOTAL_FORMS"]) + 1
# total forms = min_num + extra; min_num is already 1 so extra = total_forms - 1; extra = (total + 1) - 1; extra = total
UserFormSet.extra = int(request.POST["form-TOTAL_FORMS"])
# preserve user input without binding the form by loading it as initial
initial = [
{
Expand Down

0 comments on commit 209e782

Please sign in to comment.