#26702: Document custom field subclass change requires new custom field class
--------------------------------------+--------------------
Reporter: baylee | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Related to #26586
Can't alter a custom field to have a different base field type.
Documentation should be updated to reflect this and proposed solution.
Example before state:
{{{
class CustomCharField(models.CharField):
def foo(self):
pass
class Author(models.Model):
name = CustomCharField(max_length=255)
}}}
Example of what won't work:
{{{
class CustomCharField(models.TextField):
def foo(self):
pass
class Author(models.Model):
name = CustomCharField(max_length=255)
}}}
Example of what you should change to:
{{{
class CustomFieldMixin(object):
def foo(self):
pass
class CustomCharField(CustomFieldMixin, models.CharField):
pass
class CustomTextField(CustomFieldMixin, models.TextField):
pass
class Author(models.Model):
name = CustomTextField(max_length=255)
}}}
Should also include link to:
https://docs.djangoproject.com/en/1.9/topics/migrations/#considerations-
when-removing-model-fields to explain why user must keep old field
definition around.
--
Ticket URL: <https://code.djangoproject.com/ticket/26702>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.41b342cf97b45f35fee156900eb4dee3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.