Code

Opened 2 years ago

Last modified 13 months ago

#17122 new Bug

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

Changed 2 years ago by nickname123

patch to add support for ForeignKey and ManyToMany relations

comment:1 Changed 2 years ago by nickname123

  • Cc nickname123 added
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 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 2 years ago by nickname123

simple app for testing. Add several worker instances. Then the "many testers" model uses many2many relations. "Tasks" model uses ForeignKey relations.

comment:3 Changed 2 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 supported. I will submit a new patch soon. I am working on tests.

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

Changed 2 years ago by nickname123

updated patch

Changed 2 years ago by nickname123

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

Changed 2 years ago by nickname123

improved tests

comment:4 Changed 2 years ago by nickname123

  • Needs tests set

comment:5 Changed 2 years ago by nickname123

  • Needs tests unset

Changed 2 years ago by nickname123

merged tests and patch to same diff. Run with python ./tests/runtests.py --settings=test_sqlite admin_inlines.TestInline

Changed 2 years ago by nickname123

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

comment:6 Changed 2 years ago by nickname123

  • Summary changed from 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. to 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 2 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 2 years ago by nickname123

  • Patch needs improvement set
Version 0, edited 2 years ago by nickname123 (next)

comment:8 Changed 2 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Design decision needed

comment:9 Changed 2 years ago by aaugustin

#17214 is probably a duplicate.

comment:10 Changed 13 months ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.