Ticket #10403: django-10403.diff
File django-10403.diff, 27.7 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/contrib/admin/options.py
a b 2 2 from django import forms 3 3 from django.forms.formsets import all_valid 4 4 from django.forms.models import (modelform_factory, modelformset_factory, 5 inlineformset_factory, BaseInlineFormSet)5 inlineformset_factory, InlineFormSet) 6 6 from django.contrib.contenttypes.models import ContentType 7 7 from django.contrib.admin import widgets, helpers 8 8 from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_format_dict … … 1302 1302 """ 1303 1303 model = None 1304 1304 fk_name = None 1305 formset = BaseInlineFormSet1305 formset = InlineFormSet 1306 1306 extra = 3 1307 1307 max_num = None 1308 1308 template = None … … 1332 1332 media = property(_media) 1333 1333 1334 1334 def get_formset(self, request, obj=None, **kwargs): 1335 """Returns a BaseInlineFormSet class for use in admin add/change views."""1335 """Returns a InlineFormSet class for use in admin add/change views.""" 1336 1336 if self.declared_fieldsets: 1337 1337 fields = flatten_fieldsets(self.declared_fieldsets) 1338 1338 else: -
django/contrib/admin/validation.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/contrib/admin/validation.py
a b 1 1 from django.core.exceptions import ImproperlyConfigured 2 2 from django.db import models 3 3 from django.db.models.fields import FieldDoesNotExist 4 from django.forms.models import (BaseModelForm, BaseModelFormSet, fields_for_model,4 from django.forms.models import (BaseModelForm, ModelFormSet, fields_for_model, 5 5 _get_foreign_key) 6 6 from django.contrib.admin import ListFilter, FieldListFilter 7 7 from django.contrib.admin.util import get_fields_from_path, NotRelationField … … 206 206 % cls.__name__) 207 207 208 208 # formset 209 if hasattr(cls, 'formset') and not issubclass(cls.formset, BaseModelFormSet):209 if hasattr(cls, 'formset') and not issubclass(cls.formset, ModelFormSet): 210 210 raise ImproperlyConfigured("'%s.formset' does not inherit from " 211 " BaseModelFormSet." % cls.__name__)211 "ModelFormSet." % cls.__name__) 212 212 213 213 # exclude 214 214 if hasattr(cls, 'exclude') and cls.exclude: -
django/contrib/contenttypes/generic.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/contrib/contenttypes/generic.py
a b 10 10 from django.db.models.fields.related import RelatedField, Field, ManyToManyRel 11 11 from django.db.models.loading import get_model 12 12 from django.forms import ModelForm 13 from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance13 from django.forms.models import ModelFormSet, modelformset_factory, save_instance 14 14 from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets 15 15 from django.contrib.contenttypes.models import ContentType 16 16 from django.utils.encoding import smart_unicode … … 310 310 self.multiple = True 311 311 self.through = None 312 312 313 class BaseGenericInlineFormSet( BaseModelFormSet):313 class BaseGenericInlineFormSet(ModelFormSet): 314 314 """ 315 315 A formset for generic inline objects to a parent. 316 316 """ … … 341 341 342 342 @classmethod 343 343 def get_default_prefix(cls): 344 opts = cls. model._meta344 opts = cls.form._meta.model._meta 345 345 return '-'.join((opts.app_label, opts.object_name.lower(), 346 346 cls.ct_field.name, cls.ct_fk_field.name, 347 347 )) -
django/contrib/formtools/wizard/views.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/contrib/formtools/wizard/views.py
a b 155 155 156 156 # walk through the ne created list of forms 157 157 for form in init_form_list.itervalues(): 158 if issubclass(form, formsets. BaseFormSet):159 # if the element is based on BaseFormSet (FormSet/ModelFormSet)158 if issubclass(form, formsets.FormSet): 159 # if the element is based on FormSet (FormSet/ModelFormSet) 160 160 # we need to override the form variable. 161 161 form = form.form 162 162 # check if any form contains a FileField, if yes, we need a … … 383 383 if issubclass(self.form_list[step], forms.ModelForm): 384 384 # If the form is based on ModelForm, add instance if available. 385 385 kwargs.update({'instance': self.get_form_instance(step)}) 386 elif issubclass(self.form_list[step], forms.models. BaseModelFormSet):386 elif issubclass(self.form_list[step], forms.models.ModelFormSet): 387 387 # If the form is based on ModelFormSet, add queryset if available. 388 388 kwargs.update({'queryset': self.get_form_instance(step)}) 389 389 return self.form_list[step](**kwargs) -
django/forms/formsets.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/forms/formsets.py
a b 1 import warnings 2 1 3 from forms import Form 2 from django.core.exceptions import ValidationError 4 from django.core.exceptions import ValidationError, ImproperlyConfigured 3 5 from django.utils.encoding import StrAndUnicode 4 6 from django.utils.safestring import mark_safe 5 7 from django.utils.translation import ugettext as _ … … 7 9 from widgets import Media, HiddenInput 8 10 from util import ErrorList 9 11 10 __all__ = ('BaseFormSet', ' all_valid')12 __all__ = ('BaseFormSet', 'FormSet', 'all_valid') 11 13 12 14 # special field names 13 15 TOTAL_FORM_COUNT = 'TOTAL_FORMS' … … 28 30 self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) 29 31 super(ManagementForm, self).__init__(*args, **kwargs) 30 32 31 class BaseFormSet(StrAndUnicode): 33 34 class FormSet(StrAndUnicode): 32 35 """ 33 36 A collection of instances of the same Form class. 34 37 """ 38 39 form = None 40 extra = 1 41 can_order = False 42 can_delete = False 43 max_num = None 44 35 45 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 36 46 initial=None, error_class=ErrorList): 37 47 self.is_bound = data is not None or files is not None … … 43 53 self.error_class = error_class 44 54 self._errors = None 45 55 self._non_form_errors = None 56 # check declaration of FormSet 57 if self.form is None: 58 raise ImproperlyConfigured("FormSet declaration does not contain " 59 "'form' value.") 46 60 # construct the forms in the formset 47 61 self._construct_forms() 48 62 … … 344 358 forms = u' '.join([form.as_ul() for form in self]) 345 359 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 346 360 347 def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, 348 can_delete=False, max_num=None): 361 class BaseFormSet(FormSet): 362 warnings.warn("BaseFormSet has been renamed to FormSet.", 363 PendingDeprecationWarning) 364 365 def formset_factory(form, formset=FormSet, **kwargs): 349 366 """Return a FormSet for the given form class.""" 350 attrs = {'form': form, 'extra': extra, 351 'can_order': can_order, 'can_delete': can_delete, 352 'max_num': max_num} 353 return type(form.__name__ + 'FormSet', (formset,), attrs) 367 368 warnings.warn("formset_factory is deprecated. Use a declarative FormSet " 369 "instead.", PendingDeprecationWarning) 370 371 kwargs.update({'form': form,}) 372 return type(form.__name__ + 'FormSet', (formset,), kwargs) 354 373 355 374 def all_valid(formsets): 356 375 """Returns true if every formset in formsets is valid.""" -
django/forms/models.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 django/forms/models.py
a b 3 3 and database field objects. 4 4 """ 5 5 6 import warnings 7 6 8 from django.utils.encoding import smart_unicode, force_unicode 7 9 from django.utils.datastructures import SortedDict 8 10 from django.utils.text import get_text_list, capfirst … … 16 18 from fields import Field, ChoiceField 17 19 from widgets import SelectMultiple, HiddenInput, MultipleHiddenInput 18 20 from widgets import media_property 19 from formsets import BaseFormSet, formset_factory21 from formsets import FormSet, formset_factory 20 22 21 23 __all__ = ( 22 24 'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model', … … 406 408 407 409 # ModelFormSets ############################################################## 408 410 409 class BaseModelFormSet(BaseFormSet):411 class ModelFormSet(FormSet): 410 412 """ 411 413 A ``FormSet`` for editing a queryset and/or adding new objects to it. 412 414 """ 413 model = None414 415 415 416 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 416 417 queryset=None, **kwargs): 417 418 self.queryset = queryset 418 419 defaults = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix': prefix} 419 420 defaults.update(kwargs) 420 super(BaseModelFormSet, self).__init__(**defaults) 421 super(ModelFormSet, self).__init__(**defaults) 422 423 @property 424 def model(cls): 425 return cls.form._meta.model 421 426 422 427 def initial_form_count(self): 423 428 """Returns the number of forms that are required in this FormSet.""" 424 429 if not (self.data or self.files): 425 430 return len(self.get_queryset()) 426 return super( BaseModelFormSet, self).initial_form_count()431 return super(ModelFormSet, self).initial_form_count() 427 432 428 433 def _existing_object(self, pk): 429 434 if not hasattr(self, '_object_dict'): … … 435 440 # Import goes here instead of module-level because importing 436 441 # django.db has side effects. 437 442 from django.db import connections 438 pk_key = "%s-%s" % (self.add_prefix(i), self.model._meta.pk.name) 443 pk_key = "%s-%s" % (self.add_prefix(i), 444 self.model._meta.pk.name) 439 445 pk = self.data[pk_key] 440 446 pk_field = self.model._meta.pk 441 447 pk = pk_field.get_db_prep_lookup('exact', pk, … … 445 451 kwargs['instance'] = self._existing_object(pk) 446 452 if i < self.initial_form_count() and not kwargs.get('instance'): 447 453 kwargs['instance'] = self.get_queryset()[i] 448 return super( BaseModelFormSet, self)._construct_form(i, **kwargs)454 return super(ModelFormSet, self)._construct_form(i, **kwargs) 449 455 450 456 def get_queryset(self): 451 457 if not hasattr(self, '_queryset'): … … 649 655 qs = self.model._default_manager.get_query_set() 650 656 qs = qs.using(form.instance._state.db) 651 657 form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=HiddenInput) 652 super( BaseModelFormSet, self).add_fields(form, index)658 super(ModelFormSet, self).add_fields(form, index) 653 659 654 def modelformset_factory(model, form=ModelForm, formfield_callback=None, 655 formset=BaseModelFormSet, 656 extra=1, can_delete=False, can_order=False, 657 max_num=None, fields=None, exclude=None): 660 class BaseModelFormSet(ModelFormSet): 661 warnings.warn("BaseModelFormSet has been renamed to ModelFormSet.", 662 PendingDeprecationWarning) 663 664 def modelformset_factory(model, form=ModelForm, formset=ModelFormSet, 665 formfield_callback=None, fields=None, exclude=None, **kwargs): 658 666 """ 659 667 Returns a FormSet class for the given Django model class. 660 668 """ 669 670 warnings.warn("modelformset_factory is deprecated. Use a declarative " 671 "ModelFormSet instead.", PendingDeprecationWarning) 672 673 661 674 form = modelform_factory(model, form=form, fields=fields, exclude=exclude, 662 675 formfield_callback=formfield_callback) 663 FormSet = formset_factory(form, formset, extra=extra, max_num=max_num, 664 can_order=can_order, can_delete=can_delete) 665 FormSet.model = model 666 return FormSet 667 676 return formset_factory(form, formset, **kwargs) 668 677 669 678 # InlineFormSets ############################################################# 670 679 671 class BaseInlineFormSet(BaseModelFormSet):672 """A formset for child objects related to a parent."""673 def __init__(self, data=None, files=None, instance=None,674 save_as_new=False, prefix=None, queryset=None):675 from django.db.models.fields.related import RelatedObject676 if instance is None:677 self.instance = self.fk.rel.to()678 else:679 self.instance = instance680 self.save_as_new = save_as_new681 # is there a better way to get the object descriptor?682 self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()683 if queryset is None:684 queryset = self.model._default_manager685 qs = queryset.filter(**{self.fk.name: self.instance})686 super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,687 queryset=qs)688 689 def initial_form_count(self):690 if self.save_as_new:691 return 0692 return super(BaseInlineFormSet, self).initial_form_count()693 694 695 def _construct_form(self, i, **kwargs):696 form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)697 if self.save_as_new:698 # Remove the primary key from the form's data, we are only699 # creating new instances700 form.data[form.add_prefix(self._pk_field.name)] = None701 702 # Remove the foreign key from the form's data703 form.data[form.add_prefix(self.fk.name)] = None704 705 # Set the fk value here so that the form can do it's validation.706 setattr(form.instance, self.fk.get_attname(), self.instance.pk)707 return form708 709 @classmethod710 def get_default_prefix(cls):711 from django.db.models.fields.related import RelatedObject712 return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name().replace('+','')713 714 def save_new(self, form, commit=True):715 # Use commit=False so we can assign the parent key afterwards, then716 # save the object.717 obj = form.save(commit=False)718 pk_value = getattr(self.instance, self.fk.rel.field_name)719 setattr(obj, self.fk.get_attname(), getattr(pk_value, 'pk', pk_value))720 if commit:721 obj.save()722 # form.save_m2m() can be called via the formset later on if commit=False723 if commit and hasattr(form, 'save_m2m'):724 form.save_m2m()725 return obj726 727 def add_fields(self, form, index):728 super(BaseInlineFormSet, self).add_fields(form, index)729 if self._pk_field == self.fk:730 name = self._pk_field.name731 kwargs = {'pk_field': True}732 else:733 # The foreign key field might not be on the form, so we poke at the734 # Model field to get the label, since we need that for error messages.735 name = self.fk.name736 kwargs = {737 'label': getattr(form.fields.get(name), 'label', capfirst(self.fk.verbose_name))738 }739 if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:740 kwargs['to_field'] = self.fk.rel.field_name741 742 form.fields[name] = InlineForeignKeyField(self.instance, **kwargs)743 744 # Add the generated field to form._meta.fields if it's defined to make745 # sure validation isn't skipped on that field.746 if form._meta.fields:747 if isinstance(form._meta.fields, tuple):748 form._meta.fields = list(form._meta.fields)749 form._meta.fields.append(self.fk.name)750 751 def get_unique_error_message(self, unique_check):752 unique_check = [field for field in unique_check if field != self.fk.name]753 return super(BaseInlineFormSet, self).get_unique_error_message(unique_check)754 755 756 680 def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False): 757 681 """ 758 682 Finds and returns the ForeignKey from model to parent if there is one … … 793 717 return fk 794 718 795 719 796 def inlineformset_factory(parent_model, model, form=ModelForm, 797 formset=BaseInlineFormSet, fk_name=None, 798 fields=None, exclude=None, 799 extra=3, can_order=False, can_delete=True, max_num=None, 800 formfield_callback=None): 720 721 class InlineFormSetMetaclass(type): 722 723 def __new__(cls, name, bases, attrs): 724 try: 725 parents = [b for b in bases if issubclass(b, InlineFormSet)] 726 except NameError: 727 # we are defining InlineFormSet ourselves 728 parents = None 729 730 new_class = super(InlineFormSetMetaclass, cls).__new__(cls, name, 731 bases, attrs) 732 if not parents: 733 return new_class 734 735 # Find parent model 736 parent_model = attrs.get('parent_model', None) 737 fk_name = attrs.get('fk_name', None) 738 form = attrs.get('form', None) 739 for base in parents: 740 parent_model = parent_model or getattr(base, 'parent_model', None) 741 fk_name = fk_name or getattr(base, 'fk_name', None) 742 form = form or getattr(base, 'form', None) 743 744 # enforce a max_num=1 when the foreign key 745 # to the parent model is unique. 746 if form and parent_model: 747 new_class.fk = _get_foreign_key(parent_model, 748 form._meta.model, fk_name=fk_name) 749 if new_class.fk.unique: 750 new_class.max_num = 1 751 752 new_class.parent_model = parent_model 753 new_class.fk_name = fk_name 754 new_class.form = form 755 756 return new_class 757 758 759 class InlineFormSet(ModelFormSet): 760 """A formset for child objects related to a parent.""" 761 __metaclass__ = InlineFormSetMetaclass 762 763 parent_model = None 764 fk_name = None 765 766 def __init__(self, data=None, files=None, instance=None, 767 save_as_new=False, prefix=None, queryset=None): 768 769 from django.db.models.fields.related import RelatedObject 770 if instance is None: 771 self.instance = self.fk.rel.to() 772 else: 773 self.instance = instance 774 self.save_as_new = save_as_new 775 # is there a better way to get the object descriptor? 776 self.rel_name = RelatedObject(self.fk.rel.to, self.form._meta.model, 777 self.fk).get_accessor_name() 778 if queryset is None: 779 queryset = self.form._meta.model._default_manager 780 qs = queryset.filter(**{self.fk.name: self.instance}) 781 super(InlineFormSet, self).__init__(data, files, prefix=prefix, 782 queryset=qs) 783 784 def initial_form_count(self): 785 if self.save_as_new: 786 return 0 787 return super(InlineFormSet, self).initial_form_count() 788 789 790 def _construct_form(self, i, **kwargs): 791 form = super(InlineFormSet, self)._construct_form(i, **kwargs) 792 if self.save_as_new: 793 # Remove the primary key from the form's data, we are only 794 # creating new instances 795 form.data[form.add_prefix(self._pk_field.name)] = None 796 797 # Remove the foreign key from the form's data 798 form.data[form.add_prefix(self.fk.name)] = None 799 800 # Set the fk value here so that the form can do it's validation. 801 setattr(form.instance, self.fk.get_attname(), self.instance.pk) 802 return form 803 804 @classmethod 805 def get_default_prefix(cls): 806 from django.db.models.fields.related import RelatedObject 807 fk = _get_foreign_key(cls.parent_model, cls.form._meta.model, 808 fk_name=cls.fk_name) 809 return RelatedObject(fk.rel.to, cls.form._meta.model, 810 fk).get_accessor_name().replace('+','') 811 812 def save_new(self, form, commit=True): 813 # Use commit=False so we can assign the parent key afterwards, then 814 # save the object. 815 obj = form.save(commit=False) 816 pk_value = getattr(self.instance, self.fk.rel.field_name) 817 setattr(obj, self.fk.get_attname(), getattr(pk_value, 'pk', pk_value)) 818 if commit: 819 obj.save() 820 # form.save_m2m() can be called via the formset later on if commit=False 821 if commit and hasattr(form, 'save_m2m'): 822 form.save_m2m() 823 return obj 824 825 def add_fields(self, form, index): 826 super(InlineFormSet, self).add_fields(form, index) 827 if self._pk_field == self.fk: 828 name = self._pk_field.name 829 kwargs = {'pk_field': True} 830 else: 831 # The foreign key field might not be on the form, so we poke at the 832 # Model field to get the label, since we need that for error messages. 833 name = self.fk.name 834 kwargs = { 835 'label': getattr(form.fields.get(name), 'label', capfirst(self.fk.verbose_name)) 836 } 837 if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name: 838 kwargs['to_field'] = self.fk.rel.field_name 839 840 form.fields[name] = InlineForeignKeyField(self.instance, **kwargs) 841 842 # Add the generated field to form._meta.fields if it's defined to make 843 # sure validation isn't skipped on that field. 844 if form._meta.fields: 845 if isinstance(form._meta.fields, tuple): 846 form._meta.fields = list(form._meta.fields) 847 form._meta.fields.append(self.fk.name) 848 849 def get_unique_error_message(self, unique_check): 850 unique_check = [field for field in unique_check if field != self.fk.name] 851 return super(InlineFormSet, self).get_unique_error_message(unique_check) 852 853 class BaseInlineFormSet(InlineFormSet): 854 warnings.warn("BaseInlineFormSet has been renamed to InlineFormSet.", 855 PendingDeprecationWarning) 856 857 def inlineformset_factory(parent_model, model, formset=InlineFormSet, 858 fk_name=None, **kwargs): 801 859 """ 802 860 Returns an ``InlineFormSet`` for the given kwargs. 803 861 804 862 You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey`` 805 863 to ``parent_model``. 806 864 """ 807 fk = _get_foreign_key(parent_model, model, fk_name=fk_name) 808 # enforce a max_num=1 when the foreign key to the parent model is unique. 809 if fk.unique: 810 max_num = 1 811 kwargs = { 812 'form': form, 813 'formfield_callback': formfield_callback, 865 866 warnings.warn("inlineformset_factory is deprecated. Use a declarative " 867 "InlineFormSet instead.", PendingDeprecationWarning) 868 869 kwargs.update({ 814 870 'formset': formset, 815 'extra': extra, 816 'can_delete': can_delete, 817 'can_order': can_order, 818 'fields': fields, 819 'exclude': exclude, 820 'max_num': max_num, 821 } 822 FormSet = modelformset_factory(model, **kwargs) 823 FormSet.fk = fk 824 return FormSet 871 'parent_model': parent_model, 872 'fk_name': fk_name, 873 }) 874 return modelformset_factory(model, **kwargs) 825 875 826 876 827 877 # Fields ##################################################################### -
tests/regressiontests/admin_views/models.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 tests/regressiontests/admin_views/models.py
a b 9 9 from django.core.mail import EmailMessage 10 10 from django.db import models 11 11 from django import forms 12 from django.forms.models import BaseModelFormSet12 from django.forms.models import ModelFormSet 13 13 from django.contrib.auth.models import User 14 14 from django.contrib.contenttypes import generic 15 15 from django.contrib.contenttypes.models import ContentType … … 243 243 def __unicode__(self): 244 244 return self.name 245 245 246 class BasePersonModelFormSet( BaseModelFormSet):246 class BasePersonModelFormSet(ModelFormSet): 247 247 def clean(self): 248 248 for person_dict in self.cleaned_data: 249 249 person = person_dict.get('id') -
tests/regressiontests/forms/tests/formsets.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 tests/regressiontests/forms/tests/formsets.py
a b 1 1 # -*- coding: utf-8 -*- 2 2 from django.forms import Form, CharField, IntegerField, ValidationError, DateField 3 from django.forms.formsets import formset_factory, BaseFormSet3 from django.forms.formsets import formset_factory, FormSet 4 4 from django.utils.unittest import TestCase 5 5 6 6 … … 18 18 name = CharField() 19 19 20 20 21 class BaseFavoriteDrinksFormSet( BaseFormSet):21 class BaseFavoriteDrinksFormSet(FormSet): 22 22 def clean(self): 23 23 seen_drinks = [] 24 24 … … 29 29 seen_drinks.append(drink['name']) 30 30 31 31 32 class EmptyFsetWontValidate( BaseFormSet):32 class EmptyFsetWontValidate(FormSet): 33 33 def clean(self): 34 34 raise ValidationError("Clean method called") 35 35 … … 791 791 pass 792 792 793 793 # Formets can override the default iteration order 794 class BaseReverseFormSet( BaseFormSet):794 class BaseReverseFormSet(FormSet): 795 795 def __iter__(self): 796 796 for form in reversed(self.forms): 797 797 yield form -
tests/regressiontests/model_formsets_regress/tests.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 tests/regressiontests/model_formsets_regress/tests.py
a b 1 1 from django import forms 2 2 from django.forms.formsets import BaseFormSet, DELETION_FIELD_NAME 3 3 from django.forms.util import ErrorDict, ErrorList 4 from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory, BaseModelFormSet4 from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory, ModelFormSet 5 5 from django.test import TestCase 6 6 7 7 from models import User, UserSite, Restaurant, Manager, Network, Host … … 305 305 306 306 class FormfieldShouldDeleteFormTests(TestCase): 307 307 """ 308 Regression for #14099: BaseModelFormSet should use ModelFormSet method _should_delete_form308 Regression for #14099: ModelFormSet should use ModelFormSet method _should_delete_form 309 309 """ 310 310 311 class BaseCustomDeleteModelFormSet( BaseModelFormSet, BaseCustomDeleteFormSet):311 class BaseCustomDeleteModelFormSet(ModelFormSet, BaseCustomDeleteFormSet): 312 312 """ Model FormSet with CustomDelete MixIn """ 313 313 314 314 class CustomDeleteUserForm(forms.ModelForm): -
tests/regressiontests/modeladmin/tests.py
diff -r 1640f4c5fbe1 -r 0b890d4cda73 tests/regressiontests/modeladmin/tests.py
a b 10 10 from django.contrib.admin import (SimpleListFilter, 11 11 BooleanFieldListFilter) 12 12 from django.core.exceptions import ImproperlyConfigured 13 from django.forms.models import BaseModelFormSet13 from django.forms.models import ModelFormSet 14 14 from django.forms.widgets import Select 15 15 from django.test import TestCase 16 16 from django.utils import unittest … … 1326 1326 1327 1327 self.assertRaisesRegexp( 1328 1328 ImproperlyConfigured, 1329 "'ValidationTestInline.formset' does not inherit from BaseModelFormSet.",1329 "'ValidationTestInline.formset' does not inherit from ModelFormSet.", 1330 1330 validate, 1331 1331 ValidationTestModelAdmin, 1332 1332 ValidationTestModel, 1333 1333 ) 1334 1334 1335 class RealModelFormSet( BaseModelFormSet):1335 class RealModelFormSet(ModelFormSet): 1336 1336 pass 1337 1337 1338 1338 class ValidationTestInline(TabularInline):