You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I delete a node that has children in the django-admin, I get a ForeignKey constrain IntegrityError, resulting in not deleting anything (using Postgres).
I think this is a flaw in the deleting sequence. What I think happens is this.
Take the Tree structure:
- Edition
-- Chapter
--- ContentPage
---- Module
delete a Chapter
this node has content-pages, hence remove these first
when trying to remove the content-page, it can't because there are modules refering to it
I (temp) fixed it with a pre_save signal like so:
from django.db.models.signals import pre_delete
from django.dispatch import receiver
@receiver(pre_delete)
def pre_delete(sender, instance, using, **kwargs):
if isinstance(instance, BaseTreeNode) and instance.can_have_children:
for child in instance.children.all():
child.delete()
This is my BaseTreeNode Model:
class BaseTreeNode(PolymorphicMPTTModel):
parent = PolymorphicTreeForeignKey('self', blank=True, null=True, related_name='children', verbose_name=_('parent'))
This is an example child:
class Edition(BaseTreeNode):
pass
Is there a more elegant way?
The text was updated successfully, but these errors were encountered:
When I delete a node that has children in the django-admin, I get a ForeignKey constrain IntegrityError, resulting in not deleting anything (using Postgres).
I think this is a flaw in the deleting sequence. What I think happens is this.
Take the Tree structure:
I (temp) fixed it with a pre_save signal like so:
This is my BaseTreeNode Model:
This is an example child:
Is there a more elegant way?
The text was updated successfully, but these errors were encountered: