Document ModlelAdmin.prepopulated_fields

pull/6471/head
David Bramwell 2020-09-25 08:43:39 +01:00 zatwierdzone przez Andy Babic
rodzic 9c56dfc5d0
commit e28aa6b194
1 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -199,6 +199,31 @@ excluded from the form. This is particularly useful when registering ModelAdmin
classes for models from third-party apps, where defining panel configurations
on the Model itself is more complicated.
.. _modeladmin_prepopulated_fields:
-----------------------------------
``ModelAdmin.prepopulated_fields``
-----------------------------------
**Expected value**: A dict mapping prepopulated fields to a tuple of fields to
prepopulate from
When using CreateView or EditView to create or update model instances, the
fields corresponding to the keys in the dict are prepopulated using the fields
in the corresponding tuple. The main use for this functionality is to
automatically generate the value for SlugField fields from one or more other
fields. The generated value is produced by concatenating the values of the
source fields, and then by transforming that result into a valid slug (e.g.
substituting dashes for spaces; lowercasing ASCII letters; and removing various
English stop words such as a, an, as, and similar).
Prepopulated fields arent modified by JavaScript after a value has been saved.
Its usually undesired that slugs change (which would cause an objects URL to
change if the slug is used in it).
prepopulated_fields doesnt accept DateTimeField, ForeignKey, OneToOneField,
and ManyToManyField fields.
-----------------------------------
``ModelAdmin.get_edit_handler()``