Add instrument category model

This commit is contained in:
Ramon Wenger 2022-09-13 10:49:26 +02:00
parent ae3dfdd17f
commit d172e9a005
5 changed files with 74 additions and 2 deletions

View File

@ -0,0 +1,31 @@
# Generated by Django 3.2.13 on 2022-09-13 08:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('basicknowledge', '0018_alter_basicknowledge_contents'),
]
operations = [
migrations.CreateModel(
name='InstrumentCategory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('background', models.CharField(max_length=7, verbose_name='background color')),
('foreground', models.CharField(max_length=7, verbose_name='foreground color')),
],
options={
'verbose_name_plural': 'instrument categories',
},
),
migrations.AddField(
model_name='instrumenttype',
name='new_category',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='basicknowledge.instrumentcategory'),
),
]

View File

@ -15,6 +15,18 @@ SOCIETY = 'society'
INTERDISCIPLINARY = 'interdisciplinary' INTERDISCIPLINARY = 'interdisciplinary'
class InstrumentCategory(models.Model):
name = models.CharField(max_length=255, unique=True)
background = models.CharField('background color', max_length=7)
foreground = models.CharField('foreground color', max_length=7)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = 'instrument categories'
class InstrumentType(models.Model): class InstrumentType(models.Model):
CATEGORY_CHOICES = ( CATEGORY_CHOICES = (
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'), (LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
@ -27,6 +39,12 @@ class InstrumentType(models.Model):
max_length=100, max_length=100,
choices=CATEGORY_CHOICES choices=CATEGORY_CHOICES
) )
new_category = models.ForeignKey(
InstrumentCategory,
on_delete=models.PROTECT,
null=True,
default=None
)
@property @property
def type(self): def type(self):
@ -36,7 +54,6 @@ class InstrumentType(models.Model):
return self.type return self.type
class BasicKnowledge(StrictHierarchyPage): class BasicKnowledge(StrictHierarchyPage):
parent_page_types = ['books.book'] parent_page_types = ['books.book']

View File

@ -8,5 +8,12 @@ class InstrumentAdmin(ModelAdmin):
list_display = ('title', 'new_type', 'status_string') list_display = ('title', 'new_type', 'status_string')
search_fields = ('title', 'new_type__name') search_fields = ('title', 'new_type__name')
class InstrumentCategoryAdmin(ModelAdmin):
model = InstrumentCategory
class InstrumentTypeAdmin(ModelAdmin):
model = InstrumentType
modeladmin_register(InstrumentAdmin) modeladmin_register(InstrumentAdmin)
modeladmin_register(InstrumentCategoryAdmin)
modeladmin_register(InstrumentTypeAdmin)

View File

@ -9,7 +9,8 @@ from wagtail.core.models import Page, Site
from wagtail.core.rich_text import RichText from wagtail.core.rich_text import RichText
from assignments.models import Assignment from assignments.models import Assignment
from basicknowledge.models import BasicKnowledge, INTERDISCIPLINARY, InstrumentType, LANGUAGE_COMMUNICATION, SOCIETY from basicknowledge.models import BasicKnowledge, INTERDISCIPLINARY, InstrumentCategory, InstrumentType, \
LANGUAGE_COMMUNICATION, SOCIETY
from books.blocks import AssignmentBlock, BasicKnowledgeBlock, ImageUrlBlock, LinkBlock, VideoBlock from books.blocks import AssignmentBlock, BasicKnowledgeBlock, ImageUrlBlock, LinkBlock, VideoBlock
from books.models import Book, Chapter, ContentBlock, Module, TextBlock, Topic from books.models import Book, Chapter, ContentBlock, Module, TextBlock, Topic
from core.factories import BasePageFactory, DummyImageFactory, fake, fake_paragraph, fake_title from core.factories import BasePageFactory, DummyImageFactory, fake, fake_paragraph, fake_title
@ -70,6 +71,15 @@ class TextBlockFactory(wagtail_factories.StructBlockFactory):
model = TextBlock model = TextBlock
class InstrumentCategoryFactory(factory.DjangoModelFactory):
class Meta:
model = InstrumentCategory
django_get_or_create = ('name',)
name = factory.Iterator([LANGUAGE_COMMUNICATION, SOCIETY, INTERDISCIPLINARY])
foreground = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
background = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
class InstrumentTypeFactory(factory.DjangoModelFactory): class InstrumentTypeFactory(factory.DjangoModelFactory):
class Meta: class Meta:
model = InstrumentType model = InstrumentType

View File

@ -511,6 +511,13 @@ type InstrumentBookmarkNode implements Node {
instrument: InstrumentNode! instrument: InstrumentNode!
} }
type InstrumentCategoryNode {
id: ID!
name: String!
background: String!
foreground: String!
}
type InstrumentNode implements Node { type InstrumentNode implements Node {
title: String! title: String!
slug: String! slug: String!