Update server definitions for instrument types
This commit is contained in:
parent
4ba009fbb6
commit
6407664f80
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.24 on 2021-10-31 11:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0010_auto_20211030_2004'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='instrumenttype',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.text import slugify
|
||||||
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
|
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
|
||||||
from wagtail.core.fields import RichTextField, StreamField
|
from wagtail.core.fields import RichTextField, StreamField
|
||||||
from wagtail.images.blocks import ImageChooserBlock
|
from wagtail.images.blocks import ImageChooserBlock
|
||||||
|
|
@ -20,14 +21,18 @@ class InstrumentType(models.Model):
|
||||||
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
||||||
)
|
)
|
||||||
|
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255, unique=True)
|
||||||
category = models.CharField(
|
category = models.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
choices=CATEGORY_CHOICES
|
choices=CATEGORY_CHOICES
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return slugify(self.name.lower())
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.type
|
||||||
|
|
||||||
|
|
||||||
class BasicKnowledge(StrictHierarchyPage):
|
class BasicKnowledge(StrictHierarchyPage):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import graphene
|
import graphene
|
||||||
from graphene import relay
|
from graphene import relay
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
|
||||||
|
|
||||||
from api.utils import get_object
|
from api.utils import get_object
|
||||||
from notes.models import InstrumentBookmark
|
from notes.models import InstrumentBookmark
|
||||||
|
|
@ -10,17 +9,22 @@ from .models import BasicKnowledge, InstrumentType
|
||||||
|
|
||||||
|
|
||||||
class InstrumentTypeNode(DjangoObjectType):
|
class InstrumentTypeNode(DjangoObjectType):
|
||||||
|
type = graphene.String(required=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InstrumentType
|
model = InstrumentType
|
||||||
only_fields = [
|
only_fields = [
|
||||||
'name', 'category'
|
'name', 'category', 'type', 'id'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def resolve_type(root: InstrumentType, info, **kwargs):
|
||||||
|
return root.type
|
||||||
|
|
||||||
|
|
||||||
class InstrumentNode(DjangoObjectType):
|
class InstrumentNode(DjangoObjectType):
|
||||||
bookmarks = graphene.List(InstrumentBookmarkNode)
|
bookmarks = graphene.List(InstrumentBookmarkNode)
|
||||||
type = graphene.String()
|
type = graphene.Field(InstrumentTypeNode)
|
||||||
category = graphene.String()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BasicKnowledge
|
model = BasicKnowledge
|
||||||
|
|
@ -32,11 +36,7 @@ class InstrumentNode(DjangoObjectType):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_type(root: BasicKnowledge, info, **kwargs):
|
def resolve_type(root: BasicKnowledge, info, **kwargs):
|
||||||
return root.new_type.name
|
return root.new_type
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_category(root: BasicKnowledge, info, **kwargs):
|
|
||||||
return root.new_type.category
|
|
||||||
|
|
||||||
def resolve_bookmarks(self, info, **kwargs):
|
def resolve_bookmarks(self, info, **kwargs):
|
||||||
return InstrumentBookmark.objects.filter(
|
return InstrumentBookmark.objects.filter(
|
||||||
|
|
@ -44,6 +44,7 @@ class InstrumentNode(DjangoObjectType):
|
||||||
instrument=self
|
instrument=self
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class InstrumentQuery(object):
|
class InstrumentQuery(object):
|
||||||
instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID())
|
instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID())
|
||||||
instruments = graphene.List(InstrumentNode)
|
instruments = graphene.List(InstrumentNode)
|
||||||
|
|
|
||||||
|
|
@ -606,8 +606,7 @@ type InstrumentNode implements Node {
|
||||||
contents: GenericStreamFieldType
|
contents: GenericStreamFieldType
|
||||||
id: ID!
|
id: ID!
|
||||||
bookmarks: [InstrumentBookmarkNode]
|
bookmarks: [InstrumentBookmarkNode]
|
||||||
type: String
|
type: InstrumentTypeNode
|
||||||
category: String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstrumentNodeConnection {
|
type InstrumentNodeConnection {
|
||||||
|
|
@ -627,8 +626,10 @@ enum InstrumentTypeCategory {
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstrumentTypeNode {
|
type InstrumentTypeNode {
|
||||||
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
category: InstrumentTypeCategory!
|
category: InstrumentTypeCategory!
|
||||||
|
type: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar JSONString
|
scalar JSONString
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue