mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
clean support for view namespaces in as serializer attribute
view name is prepended with namespace if existend
This commit is contained in:
parent
08fef1ac81
commit
e9dfebc9c6
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user