diff --git a/api-guide/relations.html b/api-guide/relations.html index d774972d9..d9e1a8a16 100644 --- a/api-guide/relations.html +++ b/api-guide/relations.html @@ -330,7 +330,7 @@ class Track(models.Model):
By default this field is read-write, although you can change this behavior using the read_only
flag.
Arguments:
view_name
- The view name that should be used as the target of the relationship. required.view_name
- The view name that should be used as the target of the relationship. If you're using the standard router classes this wil be a string with the format <modelname>-detail
. required.many
- If applied to a to-many relationship, you should set this argument to True
.required
- If set to False
, the field will accept values of None
or the empty-string for nullable relationships.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
.This field is always read-only.
Arguments:
view_name
- The view name that should be used as the target of the relationship. required.view_name
- The view name that should be used as the target of the relationship. If you're using the standard router classes this wil be a string with the format <model_name>-detail
. required.lookup_field
- The field on the target that should be used for the lookup. Should correspond to a URL keyword argument on the referenced view. Default is 'pk'
.format
- If using format suffixes, hyperlinked fields will use the same format suffix for the target unless overridden by using the format
argument.^accounts/$
Name: 'account-list'
^accounts/{pk}/$
Name: 'account-detail'
Note: The base_name
argument is used to specify the initial part of the view name pattern. In the example above, that's the user
or account
part.
Typically you won't need to specify the base-name
argument, but if you have a viewset where you've defined a custom get_queryset
method, then the viewset may not have any .model
or .queryset
attribute set. If you try to register that viewset you'll see an error like this:
'base_name' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.model' or '.queryset' attribute.
+
+This means you'll need to explicitly set the base_name
argument when registering the viewset, as it could not be automatically determined from the model name.
Any methods on the viewset decorated with @link
or @action
will also be routed.
For example, given a method like this on the UserViewSet
class: