diff --git a/sample_project/migrations/0002_iscousinof_ispartof_issiblingof_livesin.py b/sample_project/migrations/0002_iscousinof_ispartof_issiblingof_livesin.py new file mode 100644 index 000000000..ac8690dd6 --- /dev/null +++ b/sample_project/migrations/0002_iscousinof_ispartof_issiblingof_livesin.py @@ -0,0 +1,82 @@ +# Generated by Django 5.0.6 on 2024-08-27 08:39 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("relations", "0001_initial"), + ("sample_project", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="IsCousinOf", + fields=[ + ( + "relation_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="relations.relation", + ), + ), + ], + bases=("relations.relation",), + ), + migrations.CreateModel( + name="IsPartOf", + fields=[ + ( + "relation_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="relations.relation", + ), + ), + ], + bases=("relations.relation",), + ), + migrations.CreateModel( + name="IsSiblingOf", + fields=[ + ( + "relation_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="relations.relation", + ), + ), + ], + bases=("relations.relation",), + ), + migrations.CreateModel( + name="LivesIn", + fields=[ + ( + "relation_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="relations.relation", + ), + ), + ], + bases=("relations.relation",), + ), + ] diff --git a/sample_project/models.py b/sample_project/models.py index 867180847..db379e56c 100644 --- a/sample_project/models.py +++ b/sample_project/models.py @@ -4,6 +4,7 @@ from apis_core.apis_entities.models import AbstractEntity from apis_core.generic.abc import GenericModel from apis_core.history.models import VersionMixin +from apis_core.relations.models import Relation class Profession(GenericModel, models.Model): @@ -20,3 +21,39 @@ class Place(VersionMixin, E53_Place, AbstractEntity): class Group(VersionMixin, E74_Group, AbstractEntity): pass + + +class IsCousinOf(Relation): + subj_model = Person + obj_model = Person + + @classmethod + def reverse_name(self) -> str: + return "is cousin of" + + +class IsPartOf(Relation): + subj_model = Person + obj_model = Group + + @classmethod + def reverse_name(self) -> str: + return "consists of" + + +class IsSiblingOf(Relation): + subj_model = Person + obj_model = Person + + @classmethod + def reverse_name(self) -> str: + return "is sibling of" + + +class LivesIn(Relation): + subj_model = Person + obj_model = Place + + @classmethod + def reverse_name(self) -> str: + return "has inhabitant"