Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#10208 closed (fixed)

ModelAdmin ignores 'exclude' and 'fields' attributes of ModelForm.Meta

Reported by: Alexander Vasiljev <a.a.v.asiljev@…> Owned by: Alex
Component: Forms Version: 1.0
Severity: Keywords:
Cc: keithb, django@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This way exclusion works:

class RegionAdmin(admin.ModelAdmin):
    #form = RegionForm
    exclude = ('changed_by', 'last_changed')

admin.site.register(Region, RegionAdmin)

but this way:

class RegionAdmin(admin.ModelAdmin):
    form = RegionForm
    #exclude = ('changed_by', 'last_changed')

admin.site.register(Region, RegionAdmin)

where

class RegionForm(forms.ModelForm):
    class Meta:
        model = Region
        exclude = ('changed_by', 'last_changed')

does not. This ticket is probably related to the #8071, however there are no foreing keys in the model.

Attachments (4)

fix_10208.diff (1.6 KB) - added by keithb 6 years ago.
patch with fix and test
custom-modeladmin-form.diff (10.3 KB) - added by Alex 6 years ago.
custom-modeladmin-form.2.diff (10.7 KB) - added by Alex 6 years ago.
added an extra test
custom-modeladmin-form.3.diff (12.7 KB) - added by Alex 6 years ago.
Fixed it for InlineModelAdmin as well.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

just as a workaround until this gets fixed, you can do something like

class RegionAdmin(admin.ModelAdmin):
    form = RegionForm
    exclude = RegionForm.Meta.exclude

Unnecessary, but avoids repeating myself

comment:2 Changed 7 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 years ago by keithb

  • Owner changed from nobody to keithb
  • Status changed from new to assigned

Changed 6 years ago by keithb

patch with fix and test

comment:4 Changed 6 years ago by keithb

  • Has patch set

My fix checks the form's exclusion list if the admin's exclusion list isn't specified. Added a test to use the form described in the ticket description.

comment:5 Changed 6 years ago by keithb

  • Cc keithb added

Changed 6 years ago by Alex

Changed 6 years ago by Alex

added an extra test

comment:6 Changed 6 years ago by Alex

  • Owner changed from keithb to Alex
  • Status changed from assigned to new

Changed 6 years ago by Alex

Fixed it for InlineModelAdmin as well.

comment:7 Changed 6 years ago by jacob

  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 6 years ago by anonymous

  • Cc django@… added

comment:9 Changed 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [10619]) Fixed #10208: ModelAdmin now respects the exclude and field atributes of custom ModelForms. Thanks, Alex Gaynor.

comment:10 Changed 6 years ago by jacob

(In [10620]) [1.0.X] Fixed #10208: ModelAdmin now respects the exclude and field atributes of custom ModelForms. Thanks, Alex Gaynor. Backport of r10619 from trunk.

comment:11 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top