diff options
| author | Tom Christie | 2014-01-14 20:34:33 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-01-14 20:34:33 +0000 |
| commit | d20c49da4ae6f569d3acc243169e3c13c89a95fe (patch) | |
| tree | 6dab95c18f0e57b90933d365710b941e8765bc0e /docs/api-guide/serializers.md | |
| parent | cbd214699dd8f02d148d35bc52f96e85092a110a (diff) | |
| download | django-rest-framework-d20c49da4ae6f569d3acc243169e3c13c89a95fe.tar.bz2 | |
More HyperlinkedModelSerializer docs
Diffstat (limited to 'docs/api-guide/serializers.md')
| -rw-r--r-- | docs/api-guide/serializers.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index b05acfd5..e8369c20 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -464,6 +464,29 @@ For more specific requirements such as specifying a different lookup for each fi model = Account fields = ('url', 'account_name', 'users', 'created') +## Overiding the URL field behavior + +The name of the URL field defaults to 'url'. You can override this globally, by using the `URL_FIELD_NAME` setting. + +You can also override this on a per-serializer basis by using the `url_field_name` option on the serializer, like so: + + class AccountSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Account + fields = ('account_url', 'account_name', 'users', 'created') + url_field_name = 'account_url' + +**Note**: The generic view implementations normally generate a `Location` header in response to successful `POST` requests. Serializers using `url_field_name` option will not have this header automatically included by the view. If you need to do so you will ned to also override the view's `get_success_headers()` method. + +You can also overide the URL field's view name and lookup field without overriding the field explicitly, by using the `view_name` and `lookup_field` options, like so: + + class AccountSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Account + fields = ('account_url', 'account_name', 'users', 'created') + view_name = 'account_detail' + lookup_field='account_name' + --- # Advanced serializer usage |
