mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #30657 -- Allowed customizing Field's descriptors with a descriptor_class attribute.
Allows model fields to override the descriptor class used on the model instance attribute.
This commit is contained in:
parent
93ffa81bc5
commit
5ed20b3aa3
5 changed files with 62 additions and 3 deletions
|
@ -1793,6 +1793,16 @@ Field API reference
|
|||
|
||||
where the arguments are interpolated from the field's ``__dict__``.
|
||||
|
||||
.. attribute:: descriptor_class
|
||||
|
||||
.. versionadded:: 3.0
|
||||
|
||||
A class implementing the :py:ref:`descriptor protocol <descriptors>`
|
||||
that is instantiated and assigned to the model instance attribute. The
|
||||
constructor must accept a single argument, the ``Field`` instance.
|
||||
Overriding this class attribute allows for customizing the get and set
|
||||
behavior.
|
||||
|
||||
To map a ``Field`` to a database-specific type, Django exposes several
|
||||
methods:
|
||||
|
||||
|
|
|
@ -283,6 +283,10 @@ Models
|
|||
:class:`~django.db.models.Index` now support app label and class
|
||||
interpolation using the ``'%(app_label)s'`` and ``'%(class)s'`` placeholders.
|
||||
|
||||
* The new :attr:`.Field.descriptor_class` attribute allows model fields to
|
||||
customize the get and set behavior by overriding their
|
||||
:py:ref:`descriptors <descriptors>`.
|
||||
|
||||
Requests and Responses
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue