I am a bit stuck on trying to solve this
So I have a webapp, and decided to add a blog section using wagtail. This means I have quite a few pages and models already preexisting, that I do not want to touch, as well as some users already. I am aware of the owner field in the base Page class, but can't see a way to extend to into a m2m field.
To achieve this, I have created a custom user model at users.User. For blog community purposes, I wanted to add the option of picing an avatar and setting a biography, so I added those two (avatar and bio are newly added fields)
class User(AbstractUser):
name = models.CharField(_("Name of User as displayed to other users"), blank=True, max_length=255)
company = models.ForeignKey(Company, null=True, on_delete=models.CASCADE)
job_title = models.CharField(max_length=100)
avatar = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+')
bio = models.TextField(max_length=300, blank=True)
Then I have a classic Blogpost page, with title, body streamfield etc... However, I am trying to replace something where you can add multiple post editors, and each of them has edit rights. So I tried something like this:
First an orderable since I need many2many:
class PostAuthorsOrderable(Orderable):
page = ParentalKey("blog.BlogPost", related_name="post_authors")
author = models.ForeignKey("users.User",on_delete=models.CASCADE)
panels = [
SnippetChooserPanel("author"),
]
And then in the BlogPost page itself:
class BlogPost(Page):
...
content_panels = Page.content_panels + [
MultiFieldPanel(
[
InlinePanel("post_authors", label="Author", min_num=1, max_num=4)
],
heading="Authors (don't forget to add yourself!)"
),
...
]
However this is not working, any idea on how to achieve this? I do get the proper form in the wagtail admin, but I get an error. It tries to do a callback, presumable to find a list of all possible users to select, but it is giving a 404, presumably because the user is not registered as a snippet.
Before I try registering the user as a snippet, I wanted to get a second opinion here, because that feels a bit wrong somehow
PS: bonuspoints if you can also tell me how I can get a widget in the editor to just select authors by autocompleting their names into a text field , a bit like this: example
EDIT: When I click the button to add an Author, nothing happens, all I can see is a 404 in the console
172.19.0.1 - - [17/Nov/2021 15:26:09] "GET /admin/snippets/choose/users/user/ HTTP/1.1" 404 -
Not Found: /admin/snippets/choose/users/user/
There are a couple of options you could take:
SnippetChooserPanel to work - the only negative side effect is that it would add an 'edit' view for users under the Snippets menu that probably wouldn't be fully functional due to the custom logic that exists on user models (for example, it would most likely offer an encrypted password field rather than a human-usable one). You can safely ignore this (and it won't be shown to non-superusers unless you explicitly give them permission for it under Settings -> Groups).