Opened 6 years ago
Last modified 6 years ago
#29691 closed New feature
Support ForeignKey based model inheritance — at Initial Version
Reported by: | James Pic | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.1 |
Severity: | Normal | Keywords: | |
Cc: | James Pic | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, a model inheriting another will have a 1:1 relation with an automatically managed OneToOneField. This means a parent model instance may only have one child model instance. However, sometimes it may be interresting to have several child model instances for one parent model instance.
For example, creating a new child model with the same parent results in an error like:
django.db.utils.IntegrityError: UNIQUE constraint failed: djcall_call.callable_ptr_id
But overriding the parent field with a ForeignKey is not accepted:
django.core.exceptions.FieldError: Auto-generated field 'callable_ptr' in class 'Call' for parent_link to base class 'Callable' clashes with declared field of the same name.
Can we perhaps add an exception (not Exception!) for child models that override the automatic ptr field that is a OneToOneField, with a ForeignKey ?
Thanks