admin管理员组文章数量:1125629
I have used a person as an author on the blog page, but when I open the blog edit page, I can only see the text which first name and last name, not the person's image. How can I display the image as well?
here in above image you can see i got blank image
This is my person model
class Person(
WorkflowMixin,
DraftStateMixin,
LockableMixin,
RevisionMixin,
PreviewableMixin,
index.Indexed,
ClusterableModel,
):
first_name = models.CharField("First name", max_length=254)
last_name = models.CharField("Last name", max_length=254)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
panels = [
MultiFieldPanel(
[
FieldRowPanel(
[
FieldPanel("first_name"),
FieldPanel("last_name"),
]
)
],
"Name",
),
FieldPanel("image"),
PublishingPanel(),
]
This is relationship model
class BlogPersonRelationship(Orderable, models.Model):
page = ParentalKey(
"BlogPage", related_name="blog_person_relationship", on_delete=models.CASCADE
)
person = models.ForeignKey(
"base.Person", related_name="person_blog_relationship", on_delete=models.CASCADE
)
panels = [
FieldPanel("person"),
]
This is blog page model
class BlogPage(Page):
introduction = models.TextField(help_text="Text to describe the page", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
)
body = StreamField(
BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
)
content_panels = Page.content_panels + [
MultipleChooserPanel(
"blog_category_relationship",
chooser_field_name="category",
heading="Categories",
label="Category",
panels=None,
min_num=1,
),
FieldPanel("introduction"),
FieldPanel("image"),
FieldPanel("body"),
MultipleChooserPanel(
"blog_person_relationship",
chooser_field_name="person",
heading="Authors",
label="Author",
panels=None,
min_num=1,
)
]
here is the model code you can check now
I have used a person as an author on the blog page, but when I open the blog edit page, I can only see the text which first name and last name, not the person's image. How can I display the image as well?
here in above image you can see i got blank image
This is my person model
class Person(
WorkflowMixin,
DraftStateMixin,
LockableMixin,
RevisionMixin,
PreviewableMixin,
index.Indexed,
ClusterableModel,
):
first_name = models.CharField("First name", max_length=254)
last_name = models.CharField("Last name", max_length=254)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
panels = [
MultiFieldPanel(
[
FieldRowPanel(
[
FieldPanel("first_name"),
FieldPanel("last_name"),
]
)
],
"Name",
),
FieldPanel("image"),
PublishingPanel(),
]
This is relationship model
class BlogPersonRelationship(Orderable, models.Model):
page = ParentalKey(
"BlogPage", related_name="blog_person_relationship", on_delete=models.CASCADE
)
person = models.ForeignKey(
"base.Person", related_name="person_blog_relationship", on_delete=models.CASCADE
)
panels = [
FieldPanel("person"),
]
This is blog page model
class BlogPage(Page):
introduction = models.TextField(help_text="Text to describe the page", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
)
body = StreamField(
BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
)
content_panels = Page.content_panels + [
MultipleChooserPanel(
"blog_category_relationship",
chooser_field_name="category",
heading="Categories",
label="Category",
panels=None,
min_num=1,
),
FieldPanel("introduction"),
FieldPanel("image"),
FieldPanel("body"),
MultipleChooserPanel(
"blog_person_relationship",
chooser_field_name="person",
heading="Authors",
label="Author",
panels=None,
min_num=1,
)
]
here is the model code you can check now
Share Improve this question edited yesterday Dhruvin Kalathiya asked Jan 9 at 6:20 Dhruvin KalathiyaDhruvin Kalathiya 112 bronze badges 1- Thank you for adding details to your post. That helps a lot. I updated my answer. – Joanna Gorska Commented 10 hours ago
1 Answer
Reset to default 0If the problem you are having that the author image is not displaying in wagtail admin page, while you are editing post: If the author is a foreign key to Post or a snippet, then it will not show the image inside the wagtail form. The Wagtail default behaviour only shows images in the form if they are directly related to this Page, not foreign key.
To customise the admin you can use this solution (making a custom panel, where you render the image)
The easier solution may be to enable preview on the side, you can see the All of the page with all images from foreign keys as part of the template. A mobile phone icon is in the top right-hand corner of the Wagtail admin form. See this wagtail video that might help you. To have the preview working correctly you need to have the root page enabled (there is a warning displayed Wagtail admin if you don't have it set up). You also need the template with the right name in the right path. How to know if you have the template in the right path? If the preview gives you a yellow page stating that the template is missing, just read the error, it will tell you the exact path and file name where Wagtail is looking for the template. Alternatively in your model that inherits from Page add template=path/path/filename.html
本文标签:
版权声明:本文标题:django - In the Wagtail admin panel, the person's image is not showing on the blog edit page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736669039a1946815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论