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

self.parent reference not updating #685

Open
dwissmann opened this issue Mar 26, 2024 · 0 comments
Open

self.parent reference not updating #685

dwissmann opened this issue Mar 26, 2024 · 0 comments

Comments

@dwissmann
Copy link

Hi - first, I am really excited to use django-unicorn in a production use-case. But before I do, I need some assistance.

I have a simple model that has a self-referencing foreign key to for a parent-child relationship. A parent can have multiple children and a child can only have one parent (a tree structure). See here:

class Tree(models.Model):
    BRANCH_TYPE = {
        "B": "Branch",
        "L": "Leaf",
        "E": "External Choice",
    }
    title = models.CharField(max_length=255)
    desc = models.CharField(max_length=1024)
    type = models.CharField(max_length=1, choices=BRANCH_TYPE)
    external = models.CharField(max_length=1024)
    parent = models.ForeignKey('self', models.SET_NULL, null=True, blank=True, parent_link='children')
    
    def __str__(self):
        return self.title

I created a component and two child components - parent title and a list of it's children (loop) and another for adding a new child:

{% load unicorn %}
<div>
    <div class="prompt" unicorn:click="walk_back()">{{ prompt_title }}</div>
    <hr>
    <div class="childrenoptions">
    {% for option in child_options %}
        {% unicorn 'tree-walk-options' option=option key=option.id %}
    {% endfor %}
    </div>      
    {% unicorn 'tree-add-option' key=option.id %}
</div>

When I "walk the tree" (click on child who becomes the new parent) the reference in the child self.parent does not update correctly.

Is this a bug?

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