#7623: Multi-table inheritance does not allow linking new instance of child model to existing parent model instance. -------------------------------------+------------------------------------- Reporter: brooks.travis@… | Owner: nobody Type: Bug | Status: reopened Component: Database layer | Version: SVN (models, ORM) | Resolution: Severity: Normal | Triage Stage: Design Keywords: model-inheritance, | decision needed multi-table-inheritance | Needs documentation: 1 Has patch: 1 | Patch needs improvement: 1 Needs tests: 1 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+------------------------------------- Changes (by akaariai):
* cc: anssi.kaariainen@… (added) Comment: If you want to extend an existing instance, you need to copy all fields of the parent to the new child manually. Unfortunately this can't be done in a generic way using only public APIs. Although ._meta is semi-public and doing {{{ child = ChildModel(**childfields) # set child field values for field in parent._meta.fields: setattr(child, field.attname, getattr(parent, field.attname)) # set child values from parent child.parent_ptr = parent.pk # not sure if this is strictly necessary, probably so... }}} or something along those lines should work (not tested). Now, I don't think this can be officially documented without making ._meta.fields part of the public API. I would have use for a helper method that does this. -- Ticket URL: <https://code.djangoproject.com/ticket/7623#comment:18> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.