Skip to content

Commit

Permalink
feat(models): override LegacyDateMixin
Browse files Browse the repository at this point in the history
We override the apis_core shipped LegacyDateMixin with one that uses
django_intervals FuzzyDateParserField.
The migration runs through all the relevant fields and renames and
alters them.
  • Loading branch information
b1rger committed Dec 20, 2024
1 parent 638b74c commit 9fa0ca2
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Generated by Django 5.1.4 on 2024-12-20 07:33

import django_interval.fields
from django.db import migrations

migration_list = lambda model: [
migrations.RenameField(
model_name=model,
old_name='end_date_written',
new_name='end',
),
migrations.RenameField(
model_name=model,
old_name='end_start_date',
new_name='end_date_from',
),
migrations.RenameField(
model_name=model,
old_name='end_date',
new_name='end_date_sort',
),
migrations.RenameField(
model_name=model,
old_name='end_end_date',
new_name='end_date_to',
),
migrations.RenameField(
model_name=model,
old_name='start_date_written',
new_name='start',
),
migrations.RenameField(
model_name=model,
old_name='start_start_date',
new_name='start_date_from',
),
migrations.RenameField(
model_name=model,
old_name='start_date',
new_name='start_date_sort',
),
migrations.RenameField(
model_name=model,
old_name='start_end_date',
new_name='start_date_to',
),
migrations.AlterField(
model_name=model,
name='start',
field=django_interval.fields.FuzzyDateParserField(blank=True, max_length=255, null=True, verbose_name='Start'),
),
migrations.AlterField(
model_name=model,
name='end',
field=django_interval.fields.FuzzyDateParserField(blank=True, max_length=255, null=True, verbose_name='Start'),
),
]
entities = ['event', 'institution', 'person', 'place', 'work']
relations = [
'hatreligionszugehoerigkeit',
'personeventlegacyrelation',
'personinstitutionlegacyrelation',
'personpersonlegacyrelation',
'institutioninstitutionlegacyrelation',
'personplacelegacyrelation',
'personworklegacyrelation',
'placeplacelegacyrelation',
'wargeschwistervon',
'warschwagerschwaegerinvon',
'warschwiegersohnschwiegertochtervon',
'warverwandtmit',
'hattealstrauzeugenzeugin',
'warpatenkindvon',
'dissertiertebeiunter',
'wurdegeborenin',
'starbin',
'erhieltausbildungin',
'wirkteforschtehieltsichaufin',
'studiertelerntean',
'habilitiertesichan',
'warassistentinan',
'warprivatdozentinan',
'warotitoprofessorinan',
'waraotitaoprofessorinan',
'warhonorarprofessorinan',
'warehrendoktorinan',
'wartaetigfuerwirkteanbei',
'warmitgruenderinvon',
'hatteleitungsfunktionan',
'warmitgliedvon',
'wargrossvatermuttervon',
'warrektorinan',
'wardekaninan',
'promoviertean',
'kaempfteinbei',
'warprofessorinan',
'graduiertean',
'mitbiographiertunter',
'warhonorardozentinan',
'hatteleitungsfunktionbei',
'nahmteilan',
'warelternteilvon',
'warschuelerinvon',
'warverheiratetmit',
'standinkontaktmit',
'arbeitetezusammenmit',
'wurdeerhobenin',
'wargeburtstitelvon',
'fandstattin']
allmodels = entities + relations + [f"version{entity}" for entity in entities] + [f"version{relation}" for relation in relations]


class Migration(migrations.Migration):

dependencies = [
('apis_ontology', '0044_person_alternative_names_new_and_more'),
]

operations = [item for model in allmodels for item in migration_list(model)]
10 changes: 9 additions & 1 deletion apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
from django.utils.translation import gettext_lazy as _

from apis_core.apis_entities.models import AbstractEntity
from apis_core.core.models import LegacyDateMixin
from apis_core.utils.helpers import create_object_from_uri
from apis_core.generic.abc import GenericModel
from apis_core.apis_entities.abc import E53_Place
from apis_core.history.models import VersionMixin
from django_json_editor_field.fields import JSONEditorField
from django_interval.fields import FuzzyDateParserField

from auditlog.registry import auditlog


class LegacyDateMixin(models.Model):
start = FuzzyDateParserField(max_length=255, blank=True, null=True, verbose_name=_("Start"))
end = FuzzyDateParserField(max_length=255, blank=True, null=True, verbose_name=_("End"))

class Meta:
abstract = True


class OEBLBaseEntity:
pass

Expand Down

0 comments on commit 9fa0ca2

Please sign in to comment.