Opened 15 years ago

Closed 15 years ago

Last modified 13 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 Gaynor
Component: Forms Version: 1.0
Severity: Keywords:
Cc: Keith Bussell, django@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 Keith Bussell 15 years ago.
patch with fix and test
custom-modeladmin-form.diff (10.3 KB ) - added by Alex Gaynor 15 years ago.
custom-modeladmin-form.2.diff (10.7 KB ) - added by Alex Gaynor 15 years ago.
added an extra test
custom-modeladmin-form.3.diff (12.7 KB ) - added by Alex Gaynor 15 years ago.
Fixed it for InlineModelAdmin as well.

Download all attachments as: .zip

Change History (15)

comment:1 by anonymous, 15 years ago

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 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 by Keith Bussell, 15 years ago

Owner: changed from nobody to Keith Bussell
Status: newassigned

by Keith Bussell, 15 years ago

Attachment: fix_10208.diff added

patch with fix and test

comment:4 by Keith Bussell, 15 years ago

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 by Keith Bussell, 15 years ago

Cc: Keith Bussell added

by Alex Gaynor, 15 years ago

Attachment: custom-modeladmin-form.diff added

by Alex Gaynor, 15 years ago

added an extra test

comment:6 by Alex Gaynor, 15 years ago

Owner: changed from Keith Bussell to Alex Gaynor
Status: assignednew

by Alex Gaynor, 15 years ago

Fixed it for InlineModelAdmin as well.

comment:7 by Jacob, 15 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by anonymous, 15 years ago

Cc: django@… added

comment:9 by Jacob, 15 years ago

Resolution: fixed
Status: newclosed

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

comment:10 by Jacob, 15 years ago

(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 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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