Opened 5 years ago

Closed 18 months 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 5 years ago.
patch to add support for ForeignKey and ManyToMany relations
binary_uuid_primary_key.zip (6.9 KB) - added by nickname123 5 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 5 years ago.
updated patch
2011.10.31_2309_EST_tests_for_17122.zip (11.2 KB) - added by nickname123 5 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 5 years ago.
improved tests
patch_with_tests.diff (20.9 KB) - added by nickname123 5 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 5 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 5 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)

Changed 5 years ago by nickname123

Attachment: 2011.10.26_2020_EST.diff added

patch to add support for ForeignKey and ManyToMany relations

comment:1 Changed 5 years ago by nickname123

Cc: nickname123 added
Has patch: set

comment:2 Changed 5 years ago by nickname123

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.

Changed 5 years ago by nickname123

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 Changed 5 years ago by nickname123

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 fixed. I will submit a new patch soon. I am working on tests.

Version 0, edited 5 years ago by nickname123 (next)

Changed 5 years ago by nickname123

Attachment: 2011.10.28_2206.diff added

updated patch

Changed 5 years ago by nickname123

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

Changed 5 years ago by nickname123

improved tests

comment:4 Changed 5 years ago by nickname123

Needs tests: set

comment:5 Changed 5 years ago by nickname123

Needs tests: unset

Changed 5 years ago by nickname123

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

Changed 5 years ago by nickname123

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

comment:6 Changed 5 years ago by nickname123

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.

Changed 5 years ago by nickname123

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

comment:7 Changed 5 years ago by nickname123

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 5 years ago by nickname123 (previous) (diff)

comment:8 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedDesign decision needed

comment:9 Changed 5 years ago by Aymeric Augustin

#17214 is probably a duplicate.

comment:10 Changed 4 years ago by Jacob

Triage Stage: Design decision neededAccepted

comment:11 Changed 18 months ago by Claude Paroz

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