Commit 8aa68d81 authored by Jean-Baptiste's avatar Jean-Baptiste

update: improve Model methods

parent ad8961f2
Pipeline #5019 passed with stage
in 1 minute and 21 seconds
......@@ -34,9 +34,16 @@ class Model(models.Model):
def get_container_id(self):
return Model.container_id(self)
@classonlymethod
def resource(cls, instance_or_model):
if isinstance(instance_or_model, ModelBase):
return cls.container_id(instance_or_model)
else:
return cls.resource_id(instance_or_model)
@classonlymethod
def resource_id(cls, instance):
r_id = "{}{}".format(cls.container_id(instance), getattr(instance, cls.slug_field(instance)))
r_id = "{}{}".format(cls.container_id(instance), getattr(instance, cls.slug_field(instance), ""))
return cls.__clean_path(r_id)
@classonlymethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment