-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create example_integrating_wagtail_page_models_into_django_models.md
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
wagtail/example_integrating_wagtail_page_models_into_django_models.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
] | ||
|
||
``` |