T
T
to_east2018-06-18 18:28:33
Django
to_east, 2018-06-18 18:28:33

Django formset extension for ManyToMany through tables?

Greetings Toaster Members!
I managed to make a form for OneToMany tables using inlineformset_factory () with the ability to edit, but I can’t figure out which class needs to be extended in this case, to edit ManyToMany through tables, if for example there is a banal structure of posts and tags tables:

from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=128)
    tags = models.ManyToManyField('Tag', through='PostTag')

class Tag(models.Model):
    tag_name = models.CharField(max_length=128)
    posts = models.ManyToManyField(Post, through='PostTag')

class PostTag(models.Model):
    post = models.ForeignKey(Post, on_delete=models.CASCADE)
    tag = models.ForeignKey(Tag, on_delete=models.CASCADE)

I draw your attention to the fact that the tag table is being edited on another router, but here I need to edit the link of posts to existing tags. I also found a wonderful post about creating nested forms https://micropyramid.com/blog/how-to-use-nested-fo... is it possible to use such a method as in this post?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question