Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
graysham opened this issue May 19, 2021 · 0 comments
Open

Comments

@graysham
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant