Skip to content

Commit

Permalink
Merge pull request #74 from octue/natural-keys-on-service-revisions
Browse files Browse the repository at this point in the history
Add natural keys to allow export via dumpdata
  • Loading branch information
thclark authored Feb 15, 2024
2 parents 478434f + f9476e0 commit 5623a21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions django_twined/models/service_revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def get_default_tag():
return getattr(settings, "TWINED_DEFAULT_TAG", "latest")


class ServiceRevisionManager(models.Manager):
"""A custom manager to allow getting by natural key"""

def get_by_natural_key(self, namespace, name, tag):
"""Get models by natural key, allowing flexible model export/import"""
return self.get(namespace=namespace, name=name, tag=tag)


class AbstractServiceRevision(models.Model):
"""Abstract model to register available services in the system"""

Expand Down Expand Up @@ -89,6 +97,8 @@ class AbstractServiceRevision(models.Model):
help_text="The name of the GCP project in which the service resides",
)

objects = ServiceRevisionManager()

class Meta:
"""Metaclass for AbstractServiceRevision"""

Expand All @@ -100,6 +110,10 @@ class Meta:
),
]

def natural_key(self):
"""Return the natural key as a tuple"""
return (self.namespace, self.name, self.tag)

@property
def sruid(self):
"""Return the Service Revision Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-twined"
version = "0.7.3"
version = "0.8.0"
description = "A django app to manage octue services"
authors = ["Tom Clark <[email protected]>", "Marcus Lugg <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 5623a21

Please sign in to comment.