diff --git a/djangoldp/models.py b/djangoldp/models.py index 3c1afbbb3c10e4b9c7e46c6229625258d5a36bf3..7507c0bf71d37ee66f8a545e88ec289dc7b9da35 100644 --- a/djangoldp/models.py +++ b/djangoldp/models.py @@ -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