Skip to content

Commit

Permalink
refactor(models,api): remove remaining MultiSelectFields
Browse files Browse the repository at this point in the history
Remove leftover Expression edition_type field,
Character fictionality field from models.
Point to new ArrayFields and change field type
to ListField in custom API endpoints.
  • Loading branch information
koeaw committed Sep 2, 2024
1 parent a231d24 commit 11e77d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
23 changes: 16 additions & 7 deletions apis_ontology/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class ExpressionDataSerializer(serializers.ModelSerializer):
place_of_publication = PlaceDataSerializer(
required=False, allow_null=True, many=True
)
edition_type = serializers.SerializerMethodField()
edition_type = serializers.ListField(
child=serializers.CharField(allow_null=True), required=False, allow_empty=True
)
language = serializers.ListField(
child=serializers.CharField(allow_null=True), required=False, allow_empty=True
)
Expand All @@ -84,11 +86,6 @@ class Meta:
"place_of_publication",
]

def get_edition_type(self, obj) -> list["str"]:
edition_type_str = obj.get("edition_type", None)
edition_types = list(filter(None, edition_type_str.split(",")))
return get_choices_labels(edition_types, Expression.EditionTypes)


class SimpleDetailSerializer(serializers.Serializer):
id = serializers.IntegerField()
Expand Down Expand Up @@ -126,9 +123,21 @@ class RelatedWorksDict(TypedDict):


class CharacterDataSerializer(serializers.ModelSerializer):
fictionality = serializers.ListField(
child=serializers.CharField(allow_null=True), required=False, allow_empty=True
)

class Meta:
model = Character
exclude = ["self_contenttype", "data_source"]
fields = [
"forename",
"surname",
"fallback_name",
"alternative_name",
"description",
"relevancy",
"fictionality",
]


class ArchiveDataSerializer(serializers.ModelSerializer):
Expand Down
6 changes: 3 additions & 3 deletions apis_ontology/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def get_queryset(self):
title="title",
subtitle="subtitle",
edition="edition",
edition_type="edition_type",
edition_type="new_edition_type",
language="language",
publication_date="publication_date_iso_formatted",
publisher="publisher",
Expand Down Expand Up @@ -324,7 +324,7 @@ def get_queryset(self):
title="title",
subtitle="subtitle",
edition="edition",
edition_type="edition_type",
edition_type="new_edition_type",
language="language",
publication_date="publication_date_iso_formatted",
publisher="publisher",
Expand All @@ -342,7 +342,7 @@ def get_queryset(self):
surname="surname",
fallback_name="fallback_name",
relevancy="relevancy",
fictionality="fictionality",
fictionality="new_fictionality",
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.15 on 2024-09-02 09:07

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('apis_ontology', '0076_migrate_multiselectfield_data_to_arrayfields'),
]

operations = [
migrations.RemoveField(
model_name='character',
name='fictionality',
),
migrations.RemoveField(
model_name='expression',
name='edition_type',
),
migrations.RemoveField(
model_name='versioncharacter',
name='fictionality',
),
migrations.RemoveField(
model_name='versionexpression',
name='edition_type',
),
]
20 changes: 0 additions & 20 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,16 +667,6 @@ class EditionTypes(models.TextChoices):
help_text=_('Eingabe muss im Format "X-Y" erfolgen, z.B. 5-12'),
)

edition_type = MultiSelectField(
max_length=255,
choices=EditionTypes.choices,
blank=True,
default="",
editable=False,
verbose_name=_("Ausgabetyp (deprecated)"),
help_text=_("Zur Markierung speziell relevanter Ausgaben"),
)

new_edition_type = ArrayField(
base_field=models.CharField(
max_length=255,
Expand Down Expand Up @@ -912,16 +902,6 @@ class CharacterFictionality(models.TextChoices):
help_text=_("Bedeutsamkeit für den Text, Erzählfokus"),
)

fictionality = MultiSelectField(
max_length=255,
choices=CharacterFictionality.choices,
blank=False,
default="",
editable=False,
verbose_name=_("Erfindungsgrad (deprecated)"),
help_text=_("Faktizität vs. Fiktionalität"),
)

new_fictionality = ArrayField(
base_field=models.CharField(
max_length=255,
Expand Down

0 comments on commit 11e77d0

Please sign in to comment.