问题
For example, I want to build an ecommerce website using wagtail, one component is order. I think order should not wagtail Page, but simple Django model, see code below.
from django.db import models
from wagtail.admin.edit_handlers import (
FieldPanel,
StreamFieldPanel,
MultiFieldPanel,
InlinePanel,
)
from wagtail.core.fields import RichTextField
from wagtail.core.models import Page
# Since product details are shown to users, so need to have a Page for it.
class XyzProductPage(Page):
template = "product/product_page.html"
name = models.CharField(max_length=100)
desc = RichTextField(blank=False, null=True)
content_panels = Page.content_panels + [
FieldPanel("name"),
FieldPanel("desc"),
]
class XyzOrderedProduct(models.Model):
product = models.ForeignKey(
"XyzProductPage", on_delete=models.CASCADE, related_name="+"
)
order = models.ForeignKey(
"XyzOrder", on_delete=models.CASCADE, related_name="ordered_products"
)
# Orders are not shown to users, only for internal use, so use Django model
class XyzOrder(models.Model):
panels = [
# and per each order, I want to display all ordered products on wagtail admin UI,
# so I try to use this MultiFieldPanel, but doesn't seem to work, why?
MultiFieldPanel(
[InlinePanel("ordered_products", label="Ordered Product",)],
heading="Ordered Product(s)",
),
]
I also defined ModelAdmin
for the above Django models, so I can see them on wagtail admin UI.
The questions I have are
When to use wagtail Page model, when to use Django model? In the above example, orders are defined as Django models, or I should use Page?
How to properly use panels for Django models? I saw some tutorial that I could use panels for Django models, but in the above code, I want to list all ordered products in each order (i.e.
XyzOrder
) on wagtail admin UI, but it doesn't work.How to select multiple orders and bulk delete them? Looks like wagtail admin has no support for bulk select & delete for Django models, but Django admin has. So how could we do bulk select & delete?
来源:https://stackoverflow.com/questions/62581737/guidelines-for-using-wagtail-pages-or-django-models