vbv/server/vbv_lernwelt/media_library/models.py

67 lines
2.0 KiB
Python

from wagtail import blocks, fields
from wagtail.admin.panels import FieldPanel, StreamFieldPanel
from django.db import models
# Create your models here.
from wagtail.models import Page
from wagtail.documents.models import AbstractDocument, Document
from wagtail.snippets.blocks import SnippetChooserBlock
from vbv_lernwelt.media_library.content_blocks import ContentCollection
class MediaLibrary(Page):
parent_page_types = ['learnpath.LearningPath']
subpage_types = ['media_library.TopCategory']
content_panels = [
FieldPanel('title', classname="full title"),
]
class TopCategory(Page):
"""
Handlungsfelder
"""
parent_page_types = ['media_library.MediaLibrary']
subpage_types = ['media_library.Category']
content_panels = [
FieldPanel('title', classname="full title"),
]
# Todo: use wagtail collections for this... Only applicable for documents, since links etc. dont have collections
class Category(Page):
"""
Handlungsfeld. zB. Fahrzeug
"""
parent_page_types = ['media_library.TopCategory']
introduction_text = models.TextField(default='')
description = fields.RichTextField(default='')
body = fields.StreamField([('content_collection', ContentCollection())
], use_json_field=True, null=True)
content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('introduction_text', classname="introduction text"),
FieldPanel('description', classname="introduction text"),
StreamFieldPanel('body')
]
class LibraryDocument(AbstractDocument):
# Todo: check https://filepreviews.io/
# Custom field example:
display_text = models.CharField(max_length=1024, default='')
description = models.TextField(default='')
link_display_text = models.CharField(max_length=1024, default='')
thumbnail = models.URLField()
admin_form_fields = Document.admin_form_fields + (
'display_text', 'description', 'link_display_text', 'thumbnail'
)