Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
Multiple authors for blogpost

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/
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There are a couple of options you could take:

  1. Are you sure you need to use a User model for this? If this is just being used to attach a name / photo / bio to a blog post, it could potentially just be a plain Django model registered as a snippet, separate to your user accounts.
  2. You could register the user model as a snippet, as you suggest, and this would allow 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).
  3. There are a few third-party add-ons for Wagtail that provide a chooser for non-Snippet models - see wagtailmodelchooser and wagtail-generic-chooser.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda