Last active
May 19, 2023 01:17
-
-
Save cnk/6b9415c85f175197d87d5d0965b7e815 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from wagtail.admin.panels import FieldPanel, InlinePanel, ObjectList, TabbedInterface | |
from wagtail.models import Page, Orderable, RevisionMixin | |
from wagtail.snippets.models import register_snippet | |
from modelcluster.fields import ParentalKey | |
## imports truncated so may not be 100% complete | |
class CourseDepartment(Orderable): | |
course = ParentalKey('core.CoursePage', related_name='coursedepartments', on_delete=models.CASCADE) | |
department = models.ForeignKey('core.Department', related_name='coursedepartments', on_delete=models.CASCADE) | |
panels = [ | |
FieldPanel('course'), | |
FieldPanel('department'), | |
] | |
class Meta: | |
# The ordering will affect the API | |
ordering = ['sort_order'] | |
@register_snippet | |
class Department(RevisionMixin, models.Model): | |
abbr = models.CharField( | |
verbose_name='Department Abbreviation', | |
max_length=100 | |
) | |
name = models.CharField( | |
verbose_name='Department Name', | |
max_length=100 | |
) | |
class Meta: | |
verbose_name = 'Department' | |
ordering = ['name'] | |
def __repr__(self): | |
return "<Department: {} ({})>".format(self.name, self.abbr) | |
class CoursePage(Page): | |
course_number = models.CharField( | |
verbose_name='Course Number', | |
max_length=256, | |
help_text="Only the numeric part", | |
) | |
class Meta: | |
verbose_name = 'Catalog Course' | |
verbose_name_plural = 'Catalog Courses' | |
content_panels = [ | |
FieldPanel('title'), | |
InlinePanel('coursedepartments', label="Departments", min_num=1), | |
FieldPanel('course_number'), | |
CommentPanel() | |
# We don't need the promote or publish tabs so combine everything into one content tab | |
edit_handler = TabbedInterface([ | |
ObjectList(content_panels, heading='Content'), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment