Opened 12 years ago

Closed 9 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)

2011.10.26_2020_EST.diff (1.9 KB ) - added by nickname123 12 years ago.
patch to add support for ForeignKey and ManyToMany relations
binary_uuid_primary_key.zip (6.9 KB ) - added by nickname123 12 years ago.
simple app for testing. Add several worker instances. Then the "many testers" model uses many2many relations. "Tasks" model uses ForeignKey relations.
2011.10.28_2206.diff (2.7 KB ) - added by nickname123 12 years ago.
updated patch
2011.10.31_2309_EST_tests_for_17122.zip (11.2 KB ) - added by nickname123 12 years ago.
initial tests. last test needs to be broken apart. uploading for progress
2011.11.01_1255_EST_tests_for_17122.zip (35.9 KB ) - added by nickname123 12 years ago.
improved tests
patch_with_tests.diff (20.9 KB ) - added by nickname123 12 years ago.
merged tests and patch to same diff. Run with python ./tests/runtests.py --settings=test_sqlite admin_inlines.TestInline
TRUNK_patch_with_widget_tests.diff (16.8 KB ) - added by nickname123 12 years ago.
Run with python ./tests/runtests.py --settings=test_sqlite admin_widgets.TestsFor17122
TRUNK_patch_with_widget_tests_to_render_and_update.diff (18.4 KB ) - added by nickname123 12 years ago.
adds a few more tests cases from the previous patch to make sure calls to has_changed work

Download all attachments as: .zip

Change History (19)

by nickname123, 12 years ago

Attachment: 2011.10.26_2020_EST.diff added

patch to add support for ForeignKey and ManyToMany relations

comment:1 by nickname123, 12 years ago

Cc: nickname123 added
Has patch: set

comment:2 by nickname123, 12 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 nickname123, 12 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 nickname123, 12 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.

Last edited 12 years ago by nickname123 (previous) (diff)

by nickname123, 12 years ago

Attachment: 2011.10.28_2206.diff added

updated patch

by nickname123, 12 years ago

initial tests. last test needs to be broken apart. uploading for progress

by nickname123, 12 years ago

improved tests

comment:4 by nickname123, 12 years ago

Needs tests: set

comment:5 by nickname123, 12 years ago

Needs tests: unset

by nickname123, 12 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 nickname123, 12 years ago

Run with python ./tests/runtests.py --settings=test_sqlite admin_widgets.TestsFor17122

comment:6 by nickname123, 12 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 nickname123, 12 years ago

adds a few more tests cases from the previous patch to make sure calls to has_changed work

comment:7 by nickname123, 12 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.

Last edited 12 years ago by nickname123 (previous) (diff)

comment:8 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed

comment:9 by Aymeric Augustin, 12 years ago

#17214 is probably a duplicate.

comment:10 by Jacob, 11 years ago

Triage Stage: Design decision neededAccepted

comment:11 by Claude Paroz, 9 years ago

Resolution: fixed
Status: newclosed

Considering that UUIDField is now part of Django and that the admin seems to work fine with it, I'm closing the ticket.

Note: See TracTickets for help on using tickets.
Back to Top