#26702 closed Cleanup/optimization (fixed)
Document custom field subclass change requires new custom field class
| Reported by: | Baylee Feore | Owned by: | Baylee Feore |
|---|---|---|---|
| Component: | Documentation | Version: | 1.9 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (10)
comment:1 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 9 years ago
comment:4 by , 9 years ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | set |
PR. I haven't reviewed it myself, but marking as needs improvement per previous comment.
comment:6 by , 9 years ago
| Patch needs improvement: | unset |
|---|
comment:7 by , 9 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
This doc patch is clear and concise, doesn't cover anything extraneous, and seems to meet all the docs guidelines.
The method/mixin part is confusing for an average reader who is searching for a simple case; I think that it should be an example separate from the original case in #26586 where no mixin is needed.