mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-27 13:24:26 +03:00
Docs on resources
This commit is contained in:
parent
325e63a3a7
commit
c1b9af8453
|
@ -256,24 +256,41 @@ class ModelResource(FormResource):
|
||||||
Also provides a get_bound_form() method which may be used by some renderers.
|
Also provides a get_bound_form() method which may be used by some renderers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""The form class that should be used for validation, or None to use model form validation."""
|
"""
|
||||||
|
The form class that should be used for request validation.
|
||||||
|
If set to ``None`` then the default model form validation will be used.
|
||||||
|
"""
|
||||||
form = None
|
form = None
|
||||||
|
|
||||||
"""The model class from which the model form should be constructed if no form is set."""
|
"""
|
||||||
|
The model class which this resource maps to.
|
||||||
|
"""
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
"""The list of fields we expect to receive as input. Fields in this list will may be received with
|
"""
|
||||||
raising non-existent field errors, even if they do not exist as fields on the ModelForm.
|
The list of fields to use on the output.
|
||||||
|
|
||||||
Setting the fields class attribute causes the exclude class attribute to be disregarded."""
|
May be any of:
|
||||||
|
|
||||||
|
The name of a model field.
|
||||||
|
The name of an attribute on the model.
|
||||||
|
The name of an attribute on the resource.
|
||||||
|
The name of an method on the model, with a signature like ``func(self)``.
|
||||||
|
The name of an method on the resource, with a signature like ``func(self, instance)``.
|
||||||
|
"""
|
||||||
fields = None
|
fields = None
|
||||||
|
|
||||||
"""The list of fields to exclude from the Model. This is only used if the fields class attribute is not set."""
|
"""
|
||||||
|
The list of fields to exclude. This is only used if ``fields`` is not set.
|
||||||
|
"""
|
||||||
exclude = ('id', 'pk')
|
exclude = ('id', 'pk')
|
||||||
|
|
||||||
|
"""
|
||||||
|
The list of fields to include. This is only used if ``fields`` is not set.
|
||||||
|
"""
|
||||||
|
include = ('url',)
|
||||||
|
|
||||||
|
|
||||||
# TODO: test the different validation here to allow for get get_absolute_url to be supplied on input and not bork out
|
|
||||||
# TODO: be really strict on fields - check they match in the handler methods. (this isn't a validator thing tho.)
|
|
||||||
def validate_request(self, data, files):
|
def validate_request(self, data, files):
|
||||||
"""
|
"""
|
||||||
Given some content as input return some cleaned, validated content.
|
Given some content as input return some cleaned, validated content.
|
||||||
|
@ -292,10 +309,12 @@ class ModelResource(FormResource):
|
||||||
|
|
||||||
|
|
||||||
def get_bound_form(self, content=None):
|
def get_bound_form(self, content=None):
|
||||||
"""Given some content return a Django form bound to that content.
|
"""
|
||||||
|
Given some content return a ``Form`` instance bound to that content.
|
||||||
|
|
||||||
If the form class attribute has been explicitly set then use that class to create a Form,
|
If the form class attribute has been explicitly set then that class will be used
|
||||||
otherwise if model is set use that class to create a ModelForm, otherwise return None."""
|
to create the Form, otherwise the model will be used to create a ModelForm.
|
||||||
|
"""
|
||||||
|
|
||||||
if self.form:
|
if self.form:
|
||||||
# Use explict Form
|
# Use explict Form
|
||||||
|
@ -323,6 +342,10 @@ class ModelResource(FormResource):
|
||||||
def url(self, instance):
|
def url(self, instance):
|
||||||
"""
|
"""
|
||||||
Attempts to reverse resolve the url of the given model instance for this resource.
|
Attempts to reverse resolve the url of the given model instance for this resource.
|
||||||
|
|
||||||
|
Requires a ``View`` with ``InstanceMixin`` to have been created for this resource.
|
||||||
|
|
||||||
|
This method can be overridden if you need to set the resource url reversing explicitly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# dis does teh magicks...
|
# dis does teh magicks...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user