django-polymorphic-tree icon indicating copy to clipboard operation
django-polymorphic-tree copied to clipboard

What's the best way to create objects with multiple children in code?

Open graysham opened this issue 4 years ago • 0 comments

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.

graysham avatar May 19 '21 23:05 graysham