Opened 13 years ago

Closed 13 years ago

#4727 closed (fixed)

[newforms-admin] allow override of forms.BaseForm as a base class for admin forms

Reported by: Honza Král <Honza.Kral@…> Owned by: Honza Král
Component: contrib.admin Version: newforms-admin
Severity: Keywords: newforms admin form class
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a model that need some custom validation across multiple fields. To achieve that it would be best to allow overriding of base form like this:

from django import newforms as forms
class SomeModelForm( forms.BaseForm ):
    def clean( self ):
        data = self.cleaned_data
        if I_not_like_something( data ):
            raise forms.ValidationError, _( "Something is wrong" )
        return data

class SomeModelOptions( admin.ModelAdmin ):
    base_form = SomeModelForm SomeModel, SomeModelOptions )

Since newforms.models.form_for_instance and newforms.models.form_for_instance already provide this functionality, its just a matter of adding the variable to ModelAdmin.

This approach would also solve #4507

Attachments (2)

newforms-admin-5559-allow-form-base-override.diff (1.8 KB) - added by Honza Král <Honza.Kral@…> 13 years ago.
newforms-admin-base-form.diff (4.2 KB) - added by Petr Marhoun <petr.marhoun@…> 13 years ago.

Download all attachments as: .zip

Change History (8)

Changed 13 years ago by Honza Král <Honza.Kral@…>

comment:1 Changed 13 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 13 years ago by anonymous

+1 on this -- very easy patch provides significant new functionality.

This seems to me the easiest way of handling what I assume is a very common use case of validating across multiple fields in the admin.

comment:3 Changed 13 years ago by Honza Král

Owner: changed from nobody to Honza Král

Changed 13 years ago by Petr Marhoun <petr.marhoun@…>

comment:4 Changed 13 years ago by Petr Marhoun <petr.marhoun@…>

I attached a new patch which works also for inline formsets.

comment:5 Changed 13 years ago by Petr Marhoun <petr.marhoun@…>

I don't think that attached patches solve #4507 - see my comments.

comment:6 Changed 13 years ago by Honza Král

Resolution: fixed
Status: newclosed

fixed by add_form and change_form hooks

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