What's the best way to create objects with multiple children in code?
I am attempting to adjust code I have already written to work with polymorphic-tree and am failing to get it working.
Base setup is
ParentModel(PolymorphicMPTTModel): parent = PolymorphicTreeForeignKey('self', blank=True, null=True, related_name='children', verbose_name=_('parent'), on_delete=models.CASCADE ) some_date = models.TextField(null=True)
ChildModel(ParentModel): child_data = blah
Grandchild1Model(ChildModel): data = blah
Grandchild2Model(ChildModel): data = blah
I have tried something along the lines of
d, created = ParentModel.objects.update_or_create(some_date=blah) d2, create = ChildModel.objects.update_or_create(child_data=blah, parent = d)
This however does not seem to work. Any tips would be greatly appreciated.