From 429e3496cd4d5c95f2f40608c53bb912b612a876 Mon Sep 17 00:00:00 2001 From: KK Date: Tue, 12 Mar 2024 12:26:02 +0100 Subject: [PATCH 1/3] refactor(models): rename mixin for generic name Rename mixin used for providing entities with a generic 'name' field. --- apis_ontology/models.py | 42 ++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 04333c9..61698bb 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -52,9 +52,9 @@ class Meta: abstract = True -class NameMixin(models.Model): +class GenericNameMixin(models.Model): """ - Mixin for "name" field shared between entities. + Mixin for generic "name" field used by entities. """ name = models.CharField( @@ -455,7 +455,11 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) class WorkType( - NameMixin, AlternativeNameMixin, DescriptionMixin, StatusMixin, AbstractEntity + GenericNameMixin, + AlternativeNameMixin, + DescriptionMixin, + StatusMixin, + AbstractEntity, ): name_plural = models.CharField( max_length=255, @@ -588,7 +592,7 @@ def save(self, *args, **kwargs): @reversion.register(follow=["rootobject_ptr"]) -class Archive(NameMixin, DescriptionMixin, StatusMixin, AbstractEntity): +class Archive(GenericNameMixin, DescriptionMixin, StatusMixin, AbstractEntity): """ An institution or organisation where physical objects are stored and cared for. @@ -624,7 +628,7 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) -class PhysicalObject(NameMixin, DescriptionMixin, AbstractEntity): +class PhysicalObject(GenericNameMixin, DescriptionMixin, AbstractEntity): """ A physical object pertaining to a Work. @@ -680,7 +684,11 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) class Organisation( - NameMixin, AlternativeNameMixin, DescriptionMixin, StatusMixin, AbstractEntity + GenericNameMixin, + AlternativeNameMixin, + DescriptionMixin, + StatusMixin, + AbstractEntity, ): """ Any legal entity, or subunit of a legal entity. @@ -763,7 +771,7 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) -class MetaCharacter(NameMixin, DescriptionMixin, StatusMixin, AbstractEntity): +class MetaCharacter(GenericNameMixin, DescriptionMixin, StatusMixin, AbstractEntity): """ A composite entity to refer to related characters across works. @@ -789,7 +797,11 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) class Place( - NameMixin, AlternativeNameMixin, DescriptionMixin, StatusMixin, AbstractEntity + GenericNameMixin, + AlternativeNameMixin, + DescriptionMixin, + StatusMixin, + AbstractEntity, ): """ A real place in our world, either in the past or present. @@ -825,7 +837,11 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) class ResearchPerspective( - NameMixin, AlternativeNameMixin, DescriptionMixin, StatusMixin, AbstractEntity + GenericNameMixin, + AlternativeNameMixin, + DescriptionMixin, + StatusMixin, + AbstractEntity, ): """ Lens through which works are investigated. @@ -848,7 +864,11 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) class Topic( - NameMixin, AlternativeNameMixin, DescriptionMixin, StatusMixin, AbstractEntity + GenericNameMixin, + AlternativeNameMixin, + DescriptionMixin, + StatusMixin, + AbstractEntity, ): """ Topic with regard to content, theme. @@ -870,7 +890,7 @@ class Meta: @reversion.register(follow=["rootobject_ptr"]) -class Interpretatem(NameMixin, DescriptionMixin, StatusMixin, AbstractEntity): +class Interpretatem(GenericNameMixin, DescriptionMixin, StatusMixin, AbstractEntity): """ A conceptual object representing a specific (interpretative/scholarly) view on one or more Works. From 653385d286f9df36612391f368a427ced0f3c96e Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 18 Mar 2024 09:24:31 +0100 Subject: [PATCH 2/3] feat(models): add str method to TitlesMixin --- apis_ontology/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 61698bb..8fa6741 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -164,6 +164,9 @@ class TitlesMixin(models.Model): class Meta: abstract = True + def __str__(self): + return self.title + def full_title(self): full_title = self.title subtitle = self.subtitle From 034188129a676ec038b8e2874c40baf8c07b0534 Mon Sep 17 00:00:00 2001 From: KK Date: Mon, 18 Mar 2024 10:55:20 +0100 Subject: [PATCH 3/3] feat(models): add str method to PersonNameMixin --- apis_ontology/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 8fa6741..9a368f6 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -120,6 +120,9 @@ class PersonNameMixin(AlternativeNameMixin, models.Model): class Meta: abstract = True + def __str__(self): + return self.full_name() + def full_name(self): full_name = "" surname = self.surname