clean support for view namespaces in as serializer attribute

view name is prepended with namespace if existend
This commit is contained in:
Ludwig Kraatz 2012-11-08 15:27:32 +01:00
parent 08fef1ac81
commit e9dfebc9c6

View File

@ -480,6 +480,7 @@ class HyperlinkedModelSerializer(ModelSerializer):
"""
_options_class = HyperlinkedModelSerializerOptions
_default_view_name = '%(model_name)s-detail'
_default_view_namespace = None # default: no namespace is prepend to view_name
url = HyperlinkedIdentityField()
@ -497,7 +498,14 @@ class HyperlinkedModelSerializer(ModelSerializer):
'app_label': model_meta.app_label,
'model_name': model_meta.object_name.lower()
}
return self._default_view_name % format_kwargs
view_name = self._default_view_name % format_kwargs
if self._default_view_namespace:
return "%(namespace)s:%(view)s" % {
'view': view_name,
'namespace': self._default_view_namespace
}
else:
return view_name
def get_pk_field(self, model_field):
return None