Add new types
This commit is contained in:
parent
072258fac0
commit
ab60aaf9b8
|
|
@ -0,0 +1,56 @@
|
||||||
|
# Generated by Django 2.2.24 on 2021-10-20 12:13
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from basicknowledge.models import INTERDISCIPLINARY, LANGUAGE_COMMUNICATION, SOCIETY
|
||||||
|
|
||||||
|
|
||||||
|
def create_types(apps, schema_editor):
|
||||||
|
BasicKnowledge = apps.get_model('basicknowledge', 'BasicKnowledge')
|
||||||
|
InstrumentType = apps.get_model('basicknowledge', 'InstrumentType')
|
||||||
|
language_type=InstrumentType.objects.create(
|
||||||
|
name='Sprache & Kommunikation',
|
||||||
|
category=LANGUAGE_COMMUNICATION
|
||||||
|
)
|
||||||
|
society_type=InstrumentType.objects.create(
|
||||||
|
name='Gesellschaft',
|
||||||
|
category=SOCIETY
|
||||||
|
)
|
||||||
|
interdisciplinary_type=InstrumentType.objects.create(
|
||||||
|
name='Überfachliches Instrument',
|
||||||
|
category=INTERDISCIPLINARY
|
||||||
|
)
|
||||||
|
instruments = []
|
||||||
|
for instrument in BasicKnowledge.objects.filter(type=LANGUAGE_COMMUNICATION):
|
||||||
|
instrument.new_type=language_type
|
||||||
|
instruments.append(instrument)
|
||||||
|
for instrument in BasicKnowledge.objects.filter(type=SOCIETY):
|
||||||
|
instrument.new_type=society_type
|
||||||
|
instruments.append(instrument)
|
||||||
|
for instrument in BasicKnowledge.objects.filter(type=INTERDISCIPLINARY):
|
||||||
|
instrument.new_type=interdisciplinary_type
|
||||||
|
instruments.append(instrument)
|
||||||
|
|
||||||
|
BasicKnowledge.objects.bulk_update(instruments, ['new_type'])
|
||||||
|
|
||||||
|
|
||||||
|
def delete_types(apps, schema_editor):
|
||||||
|
BasicKnowledge = apps.get_model('basicknowledge', 'BasicKnowledge')
|
||||||
|
InstrumentType = apps.get_model('basicknowledge', 'InstrumentType')
|
||||||
|
instruments = []
|
||||||
|
for instrument in BasicKnowledge.objects.all():
|
||||||
|
instrument.new_type = None
|
||||||
|
instruments.append(instrument)
|
||||||
|
BasicKnowledge.objects.bulk_update(instruments, ['new_type'])
|
||||||
|
InstrumentType.objects.all().delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0008_auto_20211020_1202'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_types, delete_types)
|
||||||
|
]
|
||||||
|
|
@ -12,20 +12,23 @@ LANGUAGE_COMMUNICATION = 'language_communication'
|
||||||
SOCIETY = 'society'
|
SOCIETY = 'society'
|
||||||
INTERDISCIPLINARY = 'interdisciplinary'
|
INTERDISCIPLINARY = 'interdisciplinary'
|
||||||
|
|
||||||
CATEGORY_CHOICES = (
|
|
||||||
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
|
|
||||||
(SOCIETY, 'Gesellschaft'),
|
|
||||||
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class InstrumentType(models.Model):
|
class InstrumentType(models.Model):
|
||||||
|
CATEGORY_CHOICES = (
|
||||||
|
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
|
||||||
|
(SOCIETY, 'Gesellschaft'),
|
||||||
|
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
||||||
|
)
|
||||||
|
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
category = models.CharField(
|
category = models.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
choices=CATEGORY_CHOICES
|
choices=CATEGORY_CHOICES
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class BasicKnowledge(StrictHierarchyPage):
|
class BasicKnowledge(StrictHierarchyPage):
|
||||||
parent_page_types = ['books.book']
|
parent_page_types = ['books.book']
|
||||||
|
|
@ -47,9 +50,9 @@ class BasicKnowledge(StrictHierarchyPage):
|
||||||
|
|
||||||
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT)
|
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT)
|
||||||
|
|
||||||
type = models.CharField(
|
old_type = models.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
choices=CATEGORY_CHOICES
|
choices=InstrumentType.CATEGORY_CHOICES
|
||||||
)
|
)
|
||||||
|
|
||||||
content_panels = [
|
content_panels = [
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from .models import BasicKnowledge
|
||||||
|
|
||||||
class InstrumentNode(DjangoObjectType):
|
class InstrumentNode(DjangoObjectType):
|
||||||
bookmarks = graphene.List(InstrumentBookmarkNode)
|
bookmarks = graphene.List(InstrumentBookmarkNode)
|
||||||
|
type = graphene.String()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BasicKnowledge
|
model = BasicKnowledge
|
||||||
|
|
@ -20,6 +21,10 @@ class InstrumentNode(DjangoObjectType):
|
||||||
'slug', 'title', 'intro', 'type', 'contents',
|
'slug', 'title', 'intro', 'type', 'contents',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def resolve_type(root: BasicKnowledge, info, **kwargs):
|
||||||
|
return root.new_type.name
|
||||||
|
|
||||||
def resolve_bookmarks(self, info, **kwargs):
|
def resolve_bookmarks(self, info, **kwargs):
|
||||||
return InstrumentBookmark.objects.filter(
|
return InstrumentBookmark.objects.filter(
|
||||||
user=info.context.user,
|
user=info.context.user,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue