1 | | ''Part of DjangoSpecifications'' |
2 | | |
3 | | = Media and validation in newforms-admin = |
4 | | |
5 | | Attaching media (especially !JavaScript) and custom validation is a common use case for admin section. It should be easy. |
6 | | |
7 | | Currently, `get_form()` can be used to provide a custom form that can bring in !JavaScript and custom validation. But once this method is overriden, your form will not automatically get the custom admin widgets. As the automatic widgets are the main point of using admin, this is not generally acceptable. |
8 | | |
9 | | == Proposal == |
10 | | |
11 | | Customizing the admin should be possible by specifying an extension form for the admin class, preferrably with a class field: `class FooAdmin(admin.ModelAdmin): admin_form = FooAdminForm`. Overriding `get_form()` is equally acceptable. |
12 | | |
13 | | * Specifying this custom form should not disable automatic widgets |
14 | | * !JavaScript, CSS and whatnot should be merged from the inner Media class if it is present in the custom form: `class FooAdminForm(forms.BaseForm): media = forms.Media(js = ['/site_media/js/tiny_mce/tiny_mce.js'])` |
15 | | * Custom validation should be possible with the ordinary `clean_field()` and `clean()` overrides in the custom form and should not interfere with base field validation. |
16 | | |
17 | | See ticket #6866 for a patch. |
18 | | |
| 1 | This page and several others were created by a wiki user who was not and is not affiliated with the Django project. Previous contents of this and other similar pages are not and should not be confused with [http://docs.djangoproject.com/ Django's own documentation], which remains the sole source of official documentation for the Django project. |