Skip to content

Commit

Permalink
Create example_integrating_wagtail_page_models_into_django_models.md
Browse files Browse the repository at this point in the history
  • Loading branch information
williln authored Feb 26, 2024
1 parent 1afe3bd commit 7c7b927
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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'),
]

```

0 comments on commit 7c7b927

Please sign in to comment.