Skip to content

ParentalManyToManyField symmetrical=False #200

@mightym

Description

@mightym

I'm using on my BlogPost model the ParentalManyToManyField on the Model itself via self.
And I just realized that the field causes related Pages to update other Pages.

Similar to what would happen when using ManyToManyField with symmetrical=True

class BlogPost(Page):
    related_posts = ParentalManyToManyField(
        "self", blank=True, related_name="related_blog_posts"
    )
from blog.models import PostPage

one = PostPage.objects.get(id=1)
two = PostPage.objects.get(id=2)
three  = PostPage.objects.get(id=3)

one.related_posts.all()
Out[6]: <PageQuerySet []>

two.related_posts.all()
Out[7]: <PageQuerySet []>

one.related_posts.add(one)
one.related_posts.all()
Out[9]: [<PostPage: Post 1>]

two.related_posts.add(one)
two.related_posts.all()
Out[12]: [<PostPage: Post 1>]

two.related_posts.add(three)

two.related_posts.all()
Out[16]: [<PostPage: Post 1>, <PostPage: Post 3>]

one.save()
five.save()

one.related_posts.all()
Out[18]: <PageQuerySet [<PostPage: Post 1>, <PostPage: Post 2>]>

two.related_posts.all()
Out[19]: <PageQuerySet [<PostPage: Post 1>, <PostPage: Post 3>]>

So I assumed I have to use symmetrical=False. But this seems to have no effect. Am I' missing something or misunderstood the concept of ParentalManyToManyField?

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