Skip to content

Commit

Permalink
chore(sample_project): implement relations in models.py & add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Aug 28, 2024
1 parent b9aa308 commit 0330f0a
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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",),
),
]
37 changes: 37 additions & 0 deletions sample_project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"

0 comments on commit 0330f0a

Please sign in to comment.