diff --git django/forms/formsets.py django/forms/formsets.py
index eafe357..1f61ec9 100644
|
|
class BaseFormSet(object):
|
362 | 362 | |
363 | 363 | def add_fields(self, form, index): |
364 | 364 | """A hook for adding extra fields on to each form instance.""" |
| 365 | initial_form_count = self.initial_form_count() |
365 | 366 | if self.can_order: |
366 | 367 | # Only pre-fill the ordering field for initial forms. |
367 | | if index is not None and index < self.initial_form_count(): |
| 368 | if index is not None and index < initial_form_count: |
368 | 369 | form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_('Order'), initial=index + 1, required=False) |
369 | 370 | else: |
370 | 371 | form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_('Order'), required=False) |
371 | | if self.can_delete: |
| 372 | if self.can_delete and (self.can_delete_extra or index < initial_form_count): |
372 | 373 | form.fields[DELETION_FIELD_NAME] = BooleanField(label=_('Delete'), required=False) |
373 | 374 | |
374 | 375 | def add_prefix(self, index): |
… |
… |
class BaseFormSet(object):
|
414 | 415 | |
415 | 416 | def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, |
416 | 417 | can_delete=False, max_num=None, validate_max=False, |
417 | | min_num=None, validate_min=False): |
| 418 | min_num=None, validate_min=False, can_delete_extra=True): |
418 | 419 | """Return a FormSet for the given form class.""" |
419 | 420 | if min_num is None: |
420 | 421 | min_num = DEFAULT_MIN_NUM |
… |
… |
def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
|
426 | 427 | absolute_max = max_num + DEFAULT_MAX_NUM |
427 | 428 | attrs = {'form': form, 'extra': extra, |
428 | 429 | 'can_order': can_order, 'can_delete': can_delete, |
| 430 | 'can_delete_extra': can_delete_extra, |
429 | 431 | 'min_num': min_num, 'max_num': max_num, |
430 | 432 | 'absolute_max': absolute_max, 'validate_min': validate_min, |
431 | 433 | 'validate_max': validate_max} |