Skip to content

Commit

Permalink
Merge pull request #237 from acdh-oeaw/supply-default-order
Browse files Browse the repository at this point in the history
Supply default order
  • Loading branch information
gythaogg authored Dec 12, 2024
2 parents e4f2f28 + 811e485 commit d29d559
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __str__(self):
class Meta:
verbose_name = _("Subject")
verbose_name_plural = _("Subjects")
ordering = ["name"]


class TibScholEntityMixin(models.Model):
Expand Down Expand Up @@ -113,6 +114,7 @@ class Person(
class Meta:
verbose_name = _("person")
verbose_name_plural = _("Persons")
ordering = ["name", "pk"]

def __str__(self):
return f"{self.name} ({self.pk})"
Expand Down Expand Up @@ -211,6 +213,7 @@ class Work(
class Meta:
verbose_name = _("work")
verbose_name_plural = _("Works")
ordering = ["name", "pk"]

def __str__(self):
return f"{self.name} ({self.pk})"
Expand Down Expand Up @@ -328,6 +331,7 @@ class Instance(
class Meta:
verbose_name = _("instance")
verbose_name_plural = _("Instances")
ordering = ["name", "pk"]

def __str__(self):
return f"{self.name} ({self.pk})"
Expand Down Expand Up @@ -390,14 +394,15 @@ class Meta:
abstract = True


def enforce_plural_name(sender, **kwargs):
def enforce_meta_attributes(sender, **kwargs):
if issubclass(sender, TibScholRelationMixin):
meta = sender._meta
# set verbose_name_plural to verbose_name
meta.verbose_name_plural = meta.verbose_name or sender.__name__.lower()
meta.ordering = ["subj_object_id", "obj_object_id"]


class_prepared.connect(enforce_plural_name)
class_prepared.connect(enforce_meta_attributes)


class PersonActiveAtPlace(TibScholRelationMixin):
Expand Down

0 comments on commit d29d559

Please sign in to comment.