documentation added and default value from option class

The namespace default is now the 'view_namespace' attr of a Serializer
Option class
This commit is contained in:
Ludwig Kraatz 2012-12-04 14:06:01 +01:00
parent 0a8f1d8ca9
commit 47a1f05ec0
2 changed files with 4 additions and 2 deletions

View File

@ -314,6 +314,7 @@ By default, `HyperlinkedRelatedField` is read-write, although you can change thi
**Arguments**:
* `view_name` - The view name that should be used as the target of the relationship. **required**.
* `view_namespace` - The namespace of the view, used as the target of the relationship. The default namespace can be set as HyperlinkedModelSerializerOptions attribute. If not set, it's `None`.
* `format` - If using format suffixes, hyperlinked fields will use the same format suffix for the target unless overridden by using the `format` argument.
* `queryset` - By default `ModelSerializer` classes will use the default queryset for the relationship. `Serializer` classes must either set a queryset explicitly, or set `read_only=True`.
* `slug_field` - The field on the target that should be used for the lookup. Default is `'slug'`.
@ -329,6 +330,7 @@ This field is always read-only.
**Arguments**:
* `view_name` - The view name that should be used as the target of the relationship. **required**.
* `view_namespace` - The namespace of the view, used as the target of the relationship. The default namespace can be set as HyperlinkedModelSerializerOptions attribute. If not set, it's `None`.
* `format` - If using format suffixes, hyperlinked fields will use the same format suffix for the target unless overridden by using the `format` argument.
* `slug_field` - The field on the target that should be used for the lookup. Default is `'slug'`.
* `pk_url_kwarg` - The named url parameter for the pk field lookup. Default is `pk`.

View File

@ -547,7 +547,7 @@ class HyperlinkedRelatedField(RelatedField):
return self.slug_field
def to_native(self, obj):
view_namespace = self.view_namespace
view_namespace = self.view_namespace or getattr(self.parent.opts, 'view_namespace', None)
view_name = self.view_name
if view_namespace:
view_name = '%(namespace)s:%(name)' % {'namespace': view_namespace, 'name':view_name}
@ -659,7 +659,7 @@ class HyperlinkedIdentityField(Field):
def field_to_native(self, obj, field_name):
request = self.context.get('request', None)
format = self.format or self.context.get('format', None)
view_namespace = self.view_namespace
view_namespace = self.view_namespace or getattr(self.parent.opts, 'view_namespace', None)
view_name = self.view_name
if view_namespace:
view_name = '%(namespace)s:%(name)' % {'namespace': view_namespace, 'name':view_name}