Ticket #9171: 9171-inlineformset_factory-r9082.2.diff

File 9171-inlineformset_factory-r9082.2.diff, 2.2 KB (added by Tai Lee, 16 years ago)

Also fix ModelAdmin and InlineModelAdmin to allow a tuple for exclude.

  • django/forms/models.py

     
    528528    if fk.unique:
    529529        max_num = 1
    530530    if exclude is not None:
     531        exclude = list(exclude)
    531532        exclude.append(fk.name)
    532533    else:
    533534        exclude = [fk.name]
  • django/contrib/admin/options.py

     
    266266        if self.exclude is None:
    267267            exclude = []
    268268        else:
    269             exclude = self.exclude
     269            exclude = list(self.exclude)
    270270        defaults = {
    271271            "form": self.form,
    272272            "fields": fields,
     
    780780        if self.exclude is None:
    781781            exclude = []
    782782        else:
    783             exclude = self.exclude
     783            exclude = list(self.exclude)
    784784        defaults = {
    785785            "form": self.form,
    786786            "formset": self.formset,
  • tests/regressiontests/modeladmin/models.py

     
    123123>>> ma = BandAdmin(Band, site)
    124124>>> ma.get_form(request).base_fields.keys()
    125125['name', 'sign_date']
     126
     127# You can also pass a tuple to `exclude`.
    126128 
     129>>> class BandAdmin(ModelAdmin):
     130...     exclude = ('bio',)
     131>>> ma = BandAdmin(Band, site)
     132>>> ma.get_form(request).base_fields.keys()
     133['name', 'sign_date']
     134 
    127135# Using `fields` and `exclude`.
    128136
    129137>>> class BandAdmin(ModelAdmin):
  • tests/regressiontests/inline_formsets/models.py

     
    5151Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
    5252
    5353
     54# Regression test for #9171.
     55>>> ifs = inlineformset_factory(Parent, Child, exclude=('school',), fk_name='mother')
    5456"""
    5557}
Back to Top