mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-06 06:33:05 +03:00
Updated resourceexample with seperate form.py
This commit is contained in:
parent
3a8facdb2a
commit
4e15632875
6
examples/resourceexample/forms.py
Normal file
6
examples/resourceexample/forms.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
class MyForm(forms.Form):
|
||||||
|
foo = forms.BooleanField()
|
||||||
|
bar = forms.IntegerField(help_text='Must be an integer.')
|
||||||
|
baz = forms.CharField(max_length=32, help_text='Free text. Max length 32 chars.')
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf.urls.defaults import patterns, url
|
from django.conf.urls.defaults import patterns, url
|
||||||
|
|
||||||
urlpatterns = patterns('resourceexample.views',
|
urlpatterns = patterns('resourceexample.views',
|
||||||
url(r'^$', 'ExampleResource'),
|
url(r'^$', 'ExampleResource'),
|
||||||
url(r'^(?P<num>[0-9]+)/$', 'AnotherExampleResource'),
|
url(r'^(?P<num>[0-9]+)/$', 'AnotherExampleResource'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
from django import forms
|
|
||||||
from djangorestframework.resource import Resource
|
from djangorestframework.resource import Resource
|
||||||
from djangorestframework.response import Response, status
|
from djangorestframework.response import Response, status
|
||||||
|
from resourceexample.forms import MyForm
|
||||||
|
|
||||||
class MyForm(forms.Form):
|
|
||||||
foo = forms.BooleanField()
|
|
||||||
bar = forms.IntegerField(help_text='Must be an integer.')
|
|
||||||
baz = forms.CharField(max_length=32, help_text='Free text. Max length 32 chars.')
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleResource(Resource):
|
class ExampleResource(Resource):
|
||||||
"""A basic read only resource that points to 3 other resources."""
|
"""A basic read only resource that points to 3 other resources."""
|
||||||
|
@ -16,11 +9,10 @@ class ExampleResource(Resource):
|
||||||
def get(self, request, auth):
|
def get(self, request, auth):
|
||||||
return {"Some other resources": [self.reverse(AnotherExampleResource, num=num) for num in range(3)]}
|
return {"Some other resources": [self.reverse(AnotherExampleResource, num=num) for num in range(3)]}
|
||||||
|
|
||||||
|
|
||||||
class AnotherExampleResource(Resource):
|
class AnotherExampleResource(Resource):
|
||||||
"""A basic GET-able/POST-able resource."""
|
"""A basic GET-able/POST-able resource."""
|
||||||
allowed_methods = anon_allowed_methods = ('GET', 'POST')
|
allowed_methods = anon_allowed_methods = ('GET', 'POST')
|
||||||
form = MyForm # Optional form validation on input
|
form = MyForm # Optional form validation on input (Applies in this case the POST method, but can also apply to PUT)
|
||||||
|
|
||||||
def get(self, request, auth, num):
|
def get(self, request, auth, num):
|
||||||
"""Handle GET requests"""
|
"""Handle GET requests"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user