Can't add ManytoMany fields to a Page
See original GitHub issueFor example
class BlogPage(Page):
body = RichTextField()
categories = models.ManyToManyField(BlogCategory, blank=True)
One gets ValueError “<BlogPage: foo>” needs to have a value for field “blogpage” before this many-to-many relationship can be used.
It’s caused by this https://github.com/torchbox/django-modelcluster/issues/3 https://github.com/torchbox/django-modelcluster/blob/master/modelcluster/forms.py#L260
I’ll keep trying to think of a solution. Seems like a common use case as Wordpress implements categories as a M2M (you can pick multiple, but they are predefined unlike a tag).
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:25 (9 by maintainers)
Top Results From Across the Web
How to add data into ManyToMany field? - django
As that page states, you need to do: my_obj.categories.add(fragmentCategory.objects.get(id=1)). or my_obj.categories.create(name='val1').
Read more >The right way to use a ManyToManyField in Django
To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references...
Read more >I can't add Many-To-Many relation in Django
For many-to-many relationships add() accepts either model instances or field values, normally primary keys, as the *objs argument.
Read more >Many-to-many field, save() method and the Django admin ...
When you save a model via admin forms it's not an atomic transaction. The main object gets saved first (to make sure it...
Read more >4. How to show many to many or reverse FK fields on listview ...
You have been asked to show the childeren of each Hero, on the listview page. Hero objects have the children reverse FK attribute,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is now implemented in django-modelcluster: https://github.com/torchbox/django-modelcluster/pull/62
From initial tests, it seems to be working nicely with Wagtail: just use ParentalManyToManyField instead of ManyToManyField, and specify it in a FieldPanel as normal.
Things that need to be done before the release of Wagtail 1.9:
django-modelcluster>=3.0,<4.0
I’ve just come up against exactly the scenario bufke raised in the initial comment - the need to provide an interface for adding categories to blog posts. The workaround using an inline is not very pretty, and tags don’t quite fulfil this particular use case. Is there really no proper M2M support in Wagtail? If not, can I add a massive +1 for this to be addressed please.