OneToOne Fields excluded from ModelForms
|Reported by:||taojian||Owned by:||nobody|
|Severity:||Keywords:||OneToOne, ModelForm, ModelAdmin|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.