From 7c7b927fe9038a535a13c63a90bebc516da9d79b Mon Sep 17 00:00:00 2001 From: Lacey Henschel Date: Mon, 26 Feb 2024 15:15:54 -0800 Subject: [PATCH] Create example_integrating_wagtail_page_models_into_django_models.md --- ..._wagtail_page_models_into_django_models.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 wagtail/example_integrating_wagtail_page_models_into_django_models.md diff --git a/wagtail/example_integrating_wagtail_page_models_into_django_models.md b/wagtail/example_integrating_wagtail_page_models_into_django_models.md new file mode 100644 index 0000000..d80530e --- /dev/null +++ b/wagtail/example_integrating_wagtail_page_models_into_django_models.md @@ -0,0 +1,23 @@ +# Example of linking Django models to Wagtail Page models + +Using Wagtail 6. + +```python +from django.db import models +from modelcluster.fields import ParentalKey +from wagtail.models import Page +from wagtail.admin.panels import FieldPanel, InlinePanel +from wagtail.images.panels import ImageChooserPanel + +# Assuming Category and Product models are defined in your Django app +from app.models import Category + +class CategoryPage(Page): + category = models.OneToOneField(Category, on_delete=models.CASCADE, related_name="+") + + # Controls extra fields added to the Wagtail Admin + content_panels = Page.content_panels + [ + FieldPanel('category'), + ] + +```