diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 31a28cc..36cfefd 100644
a
|
b
|
class BaseModelAdmin(object):
|
67 | 67 | |
68 | 68 | def __init__(self): |
69 | 69 | self.formfield_overrides = dict(FORMFIELD_FOR_DBFIELD_DEFAULTS, **self.formfield_overrides) |
| 70 | |
| 71 | def formfield_changelist_for_dbfield(self, db_field, **kwargs): |
| 72 | """ |
| 73 | Hook for specifying the form Field instance for a given database Field |
| 74 | instance when using 'list_editable' on the changelist. |
| 75 | |
| 76 | By default, returns formfield_for_dbfield. |
| 77 | """ |
| 78 | return self.formfield_for_dbfield(db_field, **kwargs) |
70 | 79 | |
71 | 80 | def formfield_for_dbfield(self, db_field, **kwargs): |
72 | 81 | """ |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
352 | 361 | Returns a Form class for use in the Formset on the changelist page. |
353 | 362 | """ |
354 | 363 | defaults = { |
355 | | "formfield_callback": curry(self.formfield_for_dbfield, request=request), |
| 364 | "formfield_callback": curry(self.formfield_changelist_for_dbfield, request=request), |
356 | 365 | } |
357 | 366 | defaults.update(kwargs) |
358 | 367 | return modelform_factory(self.model, **defaults) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
363 | 372 | is used. |
364 | 373 | """ |
365 | 374 | defaults = { |
366 | | "formfield_callback": curry(self.formfield_for_dbfield, request=request), |
| 375 | "formfield_callback": curry(self.formfield_changelist_for_dbfield, request=request), |
367 | 376 | } |
368 | 377 | defaults.update(kwargs) |
369 | 378 | return modelformset_factory(self.model, |
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 584672e..1ade4f4 100644
a
|
b
|
you can pass a ``cacheable=True`` argument to :meth:`AdminSite.admin_view`::
|
797 | 797 | |
798 | 798 | (r'^my_view/$', self.admin_site.admin_view(self.my_view, cacheable=True)) |
799 | 799 | |
| 800 | .. method:: ModelAdmin.formfield_for_dbfield(self, db_field, **kwargs) |
| 801 | |
| 802 | The ``formfield_for_dbfield`` method on a ``ModelAdmin`` allows you to |
| 803 | override the default formfield used for a given database field. |
| 804 | |
| 805 | .. method:: ModelAdmin.formfield_changelist_for_dbfield(self, db_field, **kwargs) |
| 806 | |
| 807 | .. versionadded:: 1.2 |
| 808 | |
| 809 | The ``formfield_changelist_for_dbfield`` method on a ``ModelAdmin`` allows you to |
| 810 | override the default formfields used on a changelist page when list_editable is enabled. |
| 811 | Use this method to override a formfield only on the changelist. For example, to set |
| 812 | a CSS class for certain fields:: |
| 813 | |
| 814 | class MyModelAdmin(admin.ModelAdmin): |
| 815 | def formfield_changelist_for_dbfield(self, db_field, **kwargs): |
| 816 | field = super(MyModelAdmin, self).formfield_changelist_for_dbfield(db_field, **kwargs) |
| 817 | if db_field.name in ('short_field_1', 'short_field_2'): |
| 818 | field.widget.attrs['class']='smaller' |
| 819 | return field |
| 820 | |
| 821 | By default, this method just returns the result of ``formfield_for_dbfield``. |
| 822 | |
800 | 823 | .. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs) |
801 | 824 | |
802 | 825 | .. versionadded:: 1.1 |