Opened 18 years ago
Closed 18 years ago
#4727 closed (fixed)
[newforms-admin] allow override of forms.BaseForm as a base class for admin forms
| Reported by: | 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)
Change History (8)
by , 18 years ago
| Attachment: | newforms-admin-5559-allow-form-base-override.diff added | 
|---|
comment:1 by , 18 years ago
| Triage Stage: | Unreviewed → Design decision needed | 
|---|
comment:2 by , 18 years ago
comment:3 by , 18 years ago
| Owner: | changed from to | 
|---|
by , 18 years ago
| Attachment: | newforms-admin-base-form.diff added | 
|---|
comment:6 by , 18 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
fixed by add_form and change_form hooks
  Note:
 See   TracTickets
 for help on using tickets.
    
+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.