2015-01-17 14:01:44 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-01-17 14:25:05 +01:00
|
|
|
from rest_framework import permissions, routers, serializers, viewsets # noqa
|
2014-10-11 14:15:42 +02:00
|
|
|
|
|
|
|
router = routers.DefaultRouter()
|
2015-01-17 14:01:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RESTModelMixin:
|
|
|
|
"""
|
|
|
|
Mixin for django models which are used in our rest api.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
|
|
|
Returns the root rest instance.
|
|
|
|
|
|
|
|
Uses self as default.
|
|
|
|
"""
|
|
|
|
return self
|
|
|
|
|
|
|
|
def get_root_rest_url(self):
|
|
|
|
"""
|
|
|
|
Returns the detail url of the root model of this object.
|
|
|
|
"""
|
|
|
|
# Gets the default url-name in the same way as django rest framework
|
|
|
|
# does in relations.HyperlinkedModelSerializer
|
|
|
|
root_instance = self.get_root_rest_element()
|
|
|
|
rest_url = '%s-detail' % type(root_instance)._meta.object_name.lower()
|
|
|
|
return reverse(rest_url, args=[str(root_instance.pk)])
|