Opened 17 years ago

Closed 17 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

Description

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

admin.site.register( 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@…> 17 years ago.
newforms-admin-base-form.diff (4.2 KB ) - added by Petr Marhoun <petr.marhoun@…> 17 years ago.

Download all attachments as: .zip

Change History (8)

by Honza Král <Honza.Kral@…>, 17 years ago

comment:1 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by anonymous, 17 years ago

+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 by Honza Král, 17 years ago

Owner: changed from nobody to Honza Král

by Petr Marhoun <petr.marhoun@…>, 17 years ago

comment:4 by Petr Marhoun <petr.marhoun@…>, 17 years ago

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

comment:5 by Petr Marhoun <petr.marhoun@…>, 17 years ago

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

comment:6 by Honza Král, 17 years ago

Resolution: fixed
Status: newclosed

fixed by add_form and change_form hooks

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