Opened 18 years ago

Closed 18 years ago

Last modified 18 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: no UI/UX: no

Description

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 18 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by jkocherhans, 18 years ago

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 by jkocherhans, 18 years ago

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 by jkocherhans, 18 years ago

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?

by jkocherhans, 18 years ago

Attachment: one_to_one.diff added

comment:4 by jkocherhans, 18 years ago

Resolution: fixed
Status: newclosed

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

comment:5 by jkocherhans, 18 years ago

(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 by Adrian Holovaty, 18 years ago

milestone: Version 0.92

Milestone Version 0.92 deleted

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