Django

Code

Ticket #1681 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: jkocherhans Assigned to: adrian
Milestone: Component: Admin interface
Version: magic-removal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

one_to_one.diff (5.9 kB) - added by jkocherhans on 05/01/06 09:54:00.

Change History

04/25/06 13:02:16 changed 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.

04/25/06 17:50:17 changed 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.

04/26/06 14:30:35 changed by jkocherhans

  • summary changed from [magic-removal] Admin display for OneToOneField is broken to [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?

05/01/06 09:54:00 changed by jkocherhans

  • attachment one_to_one.diff added.

05/01/06 10:02:42 changed by jkocherhans

  • status changed from new to closed.
  • resolution set to fixed.

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

05/01/06 14:04:31 changed 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.

10/24/06 15:17:23 changed by adrian

  • milestone deleted.

Milestone Version 0.92 deleted


Add/Change #1681 ([patch][magic-removal] Admin display for OneToOneField is broken)




Change Properties
Action