diff options
| author | sarahboyce <sarahvboyce95@gmail.com> | 2022-04-01 20:21:43 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-04-06 13:05:57 +0200 |
| commit | 65effbdb101714ac98b3f143eaccadd8e4f08361 (patch) | |
| tree | 89bbbb2d6b58c3aeae7d1149149c9382af866022 /docs | |
| parent | 6991880109e35c879b71b7d9d9c154baeec12b89 (diff) | |
Fixed #33471 -- Made AlterField operation a noop when changing "choices".
This also allows customizing attributes of fields that don't affect
a column definition.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/howto/custom-model-fields.txt | 20 | ||||
| -rw-r--r-- | docs/releases/4.1.txt | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 2dedf05a11..c4621c8500 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -314,6 +314,26 @@ reconstructing the field:: new_instance = MyField(*args, **kwargs) self.assertEqual(my_field_instance.some_attribute, new_instance.some_attribute) +.. _custom-field-non_db_attrs: + +Field attributes not affecting database column definition +--------------------------------------------------------- + +.. versionadded:: 4.1 + +You can override ``Field.non_db_attrs`` to customize attributes of a field that +don't affect a column definition. It's used during model migrations to detect +no-op ``AlterField`` operations. + +For example:: + + class CommaSepField(models.Field): + + @property + def non_db_attrs(self): + return super().non_db_attrs + ("separator",) + + Changing a custom field's base class ------------------------------------ diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 4413fdfc9a..d83da638fc 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -288,6 +288,10 @@ Models on MariaDB and MySQL. For databases that do not support ``XOR``, the query will be converted to an equivalent using ``AND``, ``OR``, and ``NOT``. +* The new :ref:`Field.non_db_attrs <custom-field-non_db_attrs>` attribute + allows customizing attributes of fields that don't affect a column + definition. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ |
