Update instrument schema
This commit is contained in:
parent
3810932cac
commit
ac972c7196
|
|
@ -9,7 +9,7 @@ INTERDISCIPLINARY = 'interdisciplinary'
|
|||
CATEGORY_CHOICES = (
|
||||
(LANGUAGE_COMMUNICATION, '#DAA009', '#FFF5D9', 'Sprache & Kommunikation'),
|
||||
(SOCIETY, '#0F7CAC', '#DBEEF6', 'Gesellschaft'),
|
||||
(INTERDISCIPLINARY, '#99B53E', '#F3F9E3', 'Überfachliches Instrument'),
|
||||
(INTERDISCIPLINARY, '#99B53E', '#F3F9E3', 'Überfachliche Instrumente'),
|
||||
)
|
||||
|
||||
def create_categories(apps, schema_editor):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 3.2.13 on 2022-09-13 10:55
|
||||
|
||||
import basicknowledge.models
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('basicknowledge', '0023_alter_instrumenttype_category'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='basicknowledge',
|
||||
name='old_type',
|
||||
field=models.CharField(blank=True, choices=[('language_communication', 'Sprache & Kommunikation'), ('society', 'Gesellschaft'), ('interdisciplinary', 'Überfachliche Instrumente')], max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='instrumenttype',
|
||||
name='category',
|
||||
field=models.ForeignKey(default=basicknowledge.models.default_category, on_delete=django.db.models.deletion.PROTECT, related_name='instrument_types', to='basicknowledge.instrumentcategory'),
|
||||
),
|
||||
]
|
||||
|
|
@ -33,6 +33,7 @@ class InstrumentCategory(models.Model):
|
|||
def default_category():
|
||||
return InstrumentCategory.objects.first().pk
|
||||
|
||||
|
||||
class InstrumentType(models.Model):
|
||||
CATEGORY_CHOICES = (
|
||||
(LANGUAGE_COMMUNICATION, LANGUAGE_COMMUNICATION_LABEL),
|
||||
|
|
@ -45,7 +46,8 @@ class InstrumentType(models.Model):
|
|||
InstrumentCategory,
|
||||
on_delete=models.PROTECT,
|
||||
null=False,
|
||||
default=default_category
|
||||
default=default_category,
|
||||
related_name='instrument_types'
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -8,19 +8,29 @@ from notes.models import InstrumentBookmark
|
|||
from notes.schema import InstrumentBookmarkNode
|
||||
from .models import BasicKnowledge, InstrumentCategory, InstrumentType
|
||||
|
||||
|
||||
class InstrumentCategoryNode(DjangoObjectType):
|
||||
types = graphene.List('basicknowledge.queries.InstrumentTypeNode')
|
||||
|
||||
class Meta:
|
||||
model = InstrumentCategory
|
||||
interfaces = (relay.Node,)
|
||||
only_fields = [
|
||||
'name', 'foreground', 'background', 'id'
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def resolve_types(root: InstrumentCategory, info, **kwargs):
|
||||
return root.instrument_types.filter(instruments__isnull=False).order_by('name').distinct()
|
||||
|
||||
|
||||
class InstrumentTypeNode(DjangoObjectType):
|
||||
type = graphene.String(required=True)
|
||||
category = graphene.Field(InstrumentCategoryNode)
|
||||
|
||||
class Meta:
|
||||
model = InstrumentType
|
||||
interfaces = (relay.Node,)
|
||||
only_fields = [
|
||||
'name', 'category', 'type', 'id'
|
||||
]
|
||||
|
|
@ -58,6 +68,7 @@ class InstrumentQuery(object):
|
|||
instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID())
|
||||
instruments = graphene.List(InstrumentNode)
|
||||
instrument_types = graphene.List(InstrumentTypeNode)
|
||||
instrument_categories = graphene.List(InstrumentCategoryNode)
|
||||
|
||||
def resolve_instrument(self, info, **kwargs):
|
||||
slug = kwargs.get('slug')
|
||||
|
|
@ -74,3 +85,6 @@ class InstrumentQuery(object):
|
|||
|
||||
def resolve_instrument_types(self, info, **kwargs):
|
||||
return InstrumentType.objects.filter(instruments__isnull=False).order_by('name').distinct()
|
||||
|
||||
def resolve_instrument_categories(self, info, **kwargs):
|
||||
return InstrumentCategory.objects.all()
|
||||
|
|
|
|||
|
|
@ -516,6 +516,7 @@ type InstrumentCategoryNode {
|
|||
name: String!
|
||||
background: String!
|
||||
foreground: String!
|
||||
types: [InstrumentTypeNode]
|
||||
}
|
||||
|
||||
type InstrumentNode implements Node {
|
||||
|
|
@ -875,6 +876,7 @@ type Query {
|
|||
instrument(slug: String, id: ID): InstrumentNode
|
||||
instruments: [InstrumentNode]
|
||||
instrumentTypes: [InstrumentTypeNode]
|
||||
instrumentCategories: [InstrumentCategoryNode]
|
||||
studentSubmission(id: ID!): StudentSubmissionNode
|
||||
assignment(id: ID!): AssignmentNode
|
||||
assignments: [AssignmentNode]
|
||||
|
|
|
|||
Loading…
Reference in New Issue