Skip to content

Commit

Permalink
[1.9.x] Fixed #26702 -- Documented how to change the base class of a …
Browse files Browse the repository at this point in the history
…custom field.

Backport of 7767978 from master
  • Loading branch information
Baylee Feore authored and timgraham committed Jun 8, 2016
1 parent d22bac9 commit 4765769
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/howto/custom-model-fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,34 @@ and reconstructing the field::
new_instance = MyField(*args, **kwargs)
self.assertEqual(my_field_instance.some_attribute, new_instance.some_attribute)

Changing a custom field's base class
------------------------------------

You can't change the base class of a custom field because Django won't detect
the change and make a migration for it. For example, if you start with::

class CustomCharField(models.CharField):
...

and then decide that you want to use ``TextField`` instead, you can't change
the subclass like this::

class CustomCharField(models.TextField):
...

Instead, you must create a new custom field class and update your models to
reference it::

class CustomCharField(models.CharField):
...

class CustomTextField(models.TextField):
...

As discussed in :ref:`removing fields <migrations-removing-model-fields>`, you
must retain the original ``CustomCharField`` class as long as you have
migrations that reference it.

Documenting your custom field
-----------------------------

Expand Down

0 comments on commit 4765769

Please sign in to comment.