Opened 6 years ago

Closed 6 years ago

#8015 closed (duplicate)

OneToOne Fields excluded from ModelForms

Reported by: taojian 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: UI/UX:


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/  (revision 8032)
+++ django/db/models/fields/  (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/

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.

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #7947.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

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

Note: See TracTickets for help on using tickets.