【发布时间】:2017-01-21 05:23:28
【问题描述】:
如果我有一个多态模型:
class Father(polymorphic.model.PolymorphicModel)
还有一个没有额外字段的继承类:
class Child(Father)
当我有一个父亲的实例时,如何将它转换为一个子实例?
我试过的是:
foo = Father.objects.get(pk=1)
# foo is just a Father, no record in Child database table.
foo.polymorphic_ctype = ContentType.objects.get(app_label='myapp', model='child')
foo.save()
但没有任何改变。我希望 foo 成为 Child 对象,并且需要将其放入子数据库表中。
【问题讨论】:
标签: django django-contenttypes django-polymorphic