Commits

Anonymous committed 2a614a5

Updated resourceexample with seperate form.py

Comments (0)

Files changed (3)

examples/resourceexample/forms.py

+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.')

examples/resourceexample/urls.py

 from django.conf.urls.defaults import patterns, url
 
 urlpatterns = patterns('resourceexample.views',
-    url(r'^$',          'ExampleResource'),
+    url(r'^$',                 'ExampleResource'),
     url(r'^(?P<num>[0-9]+)/$', 'AnotherExampleResource'),
 )

examples/resourceexample/views.py

-from django import forms
 from djangorestframework.resource import Resource
 from djangorestframework.response import Response, status
-
-
-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.')
-
+from resourceexample.forms import MyForm
 
 class ExampleResource(Resource):
     """A basic read only resource that points to 3 other resources."""
     def get(self, request, auth):
         return {"Some other resources": [self.reverse(AnotherExampleResource, num=num) for num in range(3)]}
 
-
 class AnotherExampleResource(Resource):
     """A basic GET-able/POST-able resource."""
     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):
         """Handle GET requests"""