Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1681 closed defect (fixed)

[patch][magic-removal] Admin display for OneToOneField is broken

Reported by: jkocherhans Owned by: Adrian Holovaty
Component: contrib.admin Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


OneToOneField (without raw_id_admin=True) should have an html select field as an input widget in the admin system, but it's using a text input. The input's value attibute is empty on the change form as well.

Also, if even if you do use raw_id_admin-True, the value attribute of the input tag is empty on the change form.

I think a couple of methods from ForeignKey ought to be moved up to the RelatedField class so OneToOneField inherits them as well... I'll look into this more.

from django.contrib.auth.models import User
from django.contrib.sites.models import Site

class UserSite(models.Model):
    user = models.OneToOneField(User) # admin broken w/ or w/o raw_id_admin=True
    site = models.ForeignKey(Site)

Attachments (1)

one_to_one.diff (5.9 KB) - added by jkocherhans 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 12 years ago by jkocherhans

Adding ForeignKey's prepare_field_objs_and_params method to OneToOneField fixes the display issues. However, if you change the value of the OneToOneField, the changes aren't saved via the admin interface, which got me thinking... should they be? I mean, it's fixable, but should you be able to change the value of a OneToOneField? I thought you could in the trunk, but I forget.

comment:2 Changed 12 years ago by jkocherhans

After a little more research, here's what the current docs in the trunk and in magic-removal say about the issue:

  • No Place selection interface is displayed on Restaurant pages. There will be one (and only one) Restaurant for each Place.
  • On the Restaurant change list, every Place -- whether it has an associated Restaurant or not -- will be displayed. Adding a Restaurant to a Place just means filling out the required Restaurant fields.

Neither m-r or the trunk currently match either of those behaviors. Posting the issue to django-dev for feedback.

comment:3 Changed 12 years ago by jkocherhans

Summary: [magic-removal] Admin display for OneToOneField is broken[patch][magic-removal] Admin display for OneToOneField is broken

I've added a patch that makes OneToOneFields read-only when you edit them in the admin system. They also behave like ForeignKey fields when adding. raw_id_admin also works. Still no responses on the list... I'll probably apply this in the next couple of days unless I hear from someone.

Also, anyone know why patches (like the current one) don't get the pretty Trac formatting somtimes?

Changed 12 years ago by jkocherhans

Attachment: one_to_one.diff added

comment:4 Changed 12 years ago by jkocherhans

Resolution: fixed
Status: newclosed

(In [2800]) magic-removal: Fixed #1681. OneToOneField now works properly in the admin system.

comment:5 Changed 12 years ago by jkocherhans

(In [2802]) magic-removal: Refs #1681. Fixed side effect of [2800] on ManyToManyField. Unfortunately this involved copying and pasting a method for now. This ought to be cleaned up when validation-aware models land.

comment:6 Changed 12 years ago by Adrian Holovaty

milestone: Version 0.92

Milestone Version 0.92 deleted

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