Opened 16 years ago

Closed 16 years ago

#8015 closed (duplicate)

OneToOne Fields excluded from ModelForms

Reported by: Eric Abrahamsen Owned by: nobody
Component: Forms Version: 1.0-alpha
Severity: Keywords: OneToOne, ModelForm, ModelAdmin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Since r8033 all ModelForms (including those in the admin site) made from a model with a OneToOne field exclude that field from the form. This means all models with OneToOne fields raise ImproperlyConfigured errors in the admin site, unless the OneToOne field is explicitly excluded using the model's ModelAdmin configuration.

The relevant diff from that changeset:

===================================================================
--- django/db/models/fields/related.py  (revision 8032)
+++ django/db/models/fields/related.py  (revision 8033)
@@ -706,6 +706,7 @@
     """
     def __init__(self, to, to_field=None, **kwargs):
         kwargs['unique'] = True
+        kwargs['editable'] = False
         if 'num_in_admin' not in kwargs:
             kwargs['num_in_admin'] = 0
         super(OneToOneField, self).__init__(to, to_field,
OneToOneRel, **kwargs)
Index: tests/regressiontests/model_inheritance_regress/models.py
===================================================================

r8033 was related to making model inheritance work in the admin site. I'm currently at r8130, and commenting out the "kwargs['editable'] = False" line above makes everything work as expected (OneToOne fields appear in ModelForms and ModelAdmin). I'm not using model inheritance, though, so can't say if removing this line would break that – I assume it would.

Change History (1)

comment:1 by Brian Rosner, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #7947.

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