from django.contrib.auth.models import Group from django.db import models from wagtail.admin.panels import FieldPanel from wagtail.fields import RichTextField from wagtail.models import Page class HomePage(Page): body = RichTextField(blank=True) content_panels = Page.content_panels + ["body"] class CoursePage(Page): body = RichTextField(blank=True) allowed_groups = models.ForeignKey( Group, null=True, blank=True, on_delete=models.SET_NULL, related_name="course_pages", help_text="Select a group to restrict access to this course. Non-members will be prompted to purchase the course to view modules.", ) content_panels = Page.content_panels + [ FieldPanel("body"), FieldPanel("allowed_groups", heading="Allowed Groups"), ] class CourseModulePage(Page): body = RichTextField(blank=True) @property def full_title(self): if hasattr(self, "get_parent"): parent = self.get_parent() if parent and hasattr(parent, "specific"): course = parent.specific else: course = None if course and hasattr(course, "title"): return f"{course.title} – {self.title}" return self.title content_panels = Page.content_panels + ["body"]