Skip to content

Commit

Permalink
feat(models): introduce NsvisRelationMixin
Browse files Browse the repository at this point in the history
this is used to provide a custom form for all relations that removes the
collections input
  • Loading branch information
b1rger committed Feb 12, 2025
1 parent 9f5a8b9 commit 00867c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 7 additions & 0 deletions apis_instance_nsvis/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from apis_core.relations.forms import RelationForm


class NsvisRelationMixinForm(RelationForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
del self.fields["collections"]
24 changes: 14 additions & 10 deletions apis_instance_nsvis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,16 @@ class Meta:
abstract = True


class CollaboratesWith(Relation):
class NsvisRelationMixin:
pass


class CollaboratesWith(NsvisRelationMixin, Relation):
subj_model = Person
obj_model = Person


class IsMemberOf(TimespanMixin, Relation):
class IsMemberOf(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = Institution

Expand All @@ -240,7 +244,7 @@ def reverse_name(self) -> str:
return _("has as member")


class IsInventoriedIn(Relation):
class IsInventoriedIn(NsvisRelationMixin, Relation):
subj_model = Person
obj_model = Institution
contact = models.CharField(blank=True, default="", max_length=4096)
Expand All @@ -255,7 +259,7 @@ def reverse_name(self) -> str:
return _("inventories")


class IsLearningAt(TimespanMixin, Relation):
class IsLearningAt(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = EducationType

Expand All @@ -270,7 +274,7 @@ def reverse_name(self) -> str:
return _("has as student")


class WorksAs(TimespanMixin, Relation):
class WorksAs(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = ProfessionType

Expand All @@ -285,7 +289,7 @@ def reverse_name(self) -> str:
return _("practiced by")


class LivesIn(TimespanMixin, Relation):
class LivesIn(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = [Place, AddressData]

Expand All @@ -298,7 +302,7 @@ def reverse_name(self) -> str:
return _("has habitant")


class HasStudioIn(TimespanMixin, Relation):
class HasStudioIn(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = [Place, AddressData]

Expand All @@ -311,7 +315,7 @@ def reverse_name(self) -> str:
return _("is address for studio of")


class AddressInPlace(Relation):
class AddressInPlace(NsvisRelationMixin, Relation):
subj_model = AddressData
obj_model = Place

Expand All @@ -329,7 +333,7 @@ def reverse_name(self) -> str:
return _("is birth place of")


class DiedIn(Relation):
class DiedIn(NsvisRelationMixin, Relation):
subj_model = Person
obj_model = Place

Expand All @@ -342,7 +346,7 @@ def reverse_name(self) -> str:
return _("is place of death of")


class ExileIn(TimespanMixin, Relation):
class ExileIn(TimespanMixin, NsvisRelationMixin, Relation):
subj_model = Person
obj_model = Place

Expand Down

0 comments on commit 00867c1

Please sign in to comment.