Opened 13 years ago
Closed 10 years ago
#17122 closed Bug (fixed)
Admin widgets and forms do not support custom model fields that store non-unicode data in the database to be the primary key referenced by relation fields.
Reported by: | nickname123 | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | nickname123 | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Admin inlines and forms do not support custom model fields that store non-unicode data in the database to be the primary key referenced by relation fields because they call force_unicode() on raw database data when rendering widgets and determining if data has changed.
A simple solution is to call the custom field's to_python method where this occurs because to_python supports the raw database data and will return an object that supports unicode transformation.
Attachments (8)
Change History (19)
by , 13 years ago
Attachment: | 2011.10.26_2020_EST.diff added |
---|
comment:1 by , 13 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:2 by , 13 years ago
The patch I just uploaded adds support for ForeignKey and ManyToManyField relations.
The OneToOneField is not in this patch. I believe a design decision discussion would be required to implement OneToOneField support because it would have to pass its relation to the widget and currently does not do so.
by , 13 years ago
Attachment: | binary_uuid_primary_key.zip added |
---|
simple app for testing. Add several worker instances. Then the "many testers" model uses many2many relations. "Tasks" model uses ForeignKey relations.
comment:3 by , 13 years ago
I was mistaken about the OneToOne relation. I overlooked the RelatedFieldWidgetWrapper in django.contrib.admin.widgets. I now have this working for all relation fields. Inlines are also supported. I will submit a new patch soon. I am working on tests.
by , 13 years ago
Attachment: | 2011.10.31_2309_EST_tests_for_17122.zip added |
---|
initial tests. last test needs to be broken apart. uploading for progress
comment:4 by , 13 years ago
Needs tests: | set |
---|
comment:5 by , 13 years ago
Needs tests: | unset |
---|
by , 13 years ago
Attachment: | patch_with_tests.diff added |
---|
merged tests and patch to same diff. Run with python ./tests/runtests.py --settings=test_sqlite admin_inlines.TestInline
by , 13 years ago
Attachment: | TRUNK_patch_with_widget_tests.diff added |
---|
Run with python ./tests/runtests.py --settings=test_sqlite admin_widgets.TestsFor17122
comment:6 by , 13 years ago
Summary: | Admin inlines and forms do not support custom model fields that store non-unicode data in the database to be the primary key referenced by relation fields. → Admin widgets and forms do not support custom model fields that store non-unicode data in the database to be the primary key referenced by relation fields. |
---|
by , 13 years ago
Attachment: | TRUNK_patch_with_widget_tests_to_render_and_update.diff added |
---|
adds a few more tests cases from the previous patch to make sure calls to has_changed work
comment:7 by , 13 years ago
Patch needs improvement: | set |
---|
It was suggested in IRC chat that the fix should be done further upstream, i.e. in the field. The value provided to the widget should probably already be in proper Python format.
comment:8 by , 13 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:10 by , 12 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:11 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Considering that UUIDField
is now part of Django and that the admin seems to work fine with it, I'm closing the ticket.
patch to add support for ForeignKey and ManyToMany relations