skillbox/server/basicknowledge/models.py

64 lines
2.0 KiB
Python

from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import RichTextField, StreamField
from wagtail.images.blocks import ImageChooserBlock
from books.blocks import DocumentBlock, GeniallyBlock, InfogramBlock, InstrumentTextBlock, LinkBlock, SectionTitleBlock, \
SubtitleBlock, ThinglinkBlock, VideoBlock
from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage
LANGUAGE_COMMUNICATION = 'language_communication'
SOCIETY = 'society'
INTERDISCIPLINARY = 'interdisciplinary'
CATEGORY_CHOICES = (
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
(SOCIETY, 'Gesellschaft'),
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
)
class InstrumentType(models.Model):
name = models.CharField(max_length=255)
category = models.CharField(
max_length=100,
choices=CATEGORY_CHOICES
)
class BasicKnowledge(StrictHierarchyPage):
parent_page_types = ['books.book']
intro = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES, default='', blank=True)
contents = StreamField([
('text_block', InstrumentTextBlock()),
('image_block', ImageChooserBlock()),
('link_block', LinkBlock()),
('video_block', VideoBlock()),
('document_block', DocumentBlock()),
('section_title', SectionTitleBlock()),
('infogram_block', InfogramBlock()),
('genially_block', GeniallyBlock()),
('thinglink_block', ThinglinkBlock()),
('subtitle', SubtitleBlock()),
], null=True, blank=True)
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT)
type = models.CharField(
max_length=100,
choices=CATEGORY_CHOICES
)
content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('type'),
FieldPanel('intro'),
StreamFieldPanel('contents')
]
class Meta:
verbose_name = 'Instrument'