Skip to content

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

Description

@graysham

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions