diff options
| author | tom christie tom@tomchristie.com | 2011-02-01 22:37:51 +0000 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-02-01 22:37:51 +0000 |
| commit | 6ce5b643fbeab322d85dbaed87d11ffb950c5bed (patch) | |
| tree | e08ad4cc8f465390564a3003daf8cf04b708438b /examples/resourceexample/views.py | |
| parent | 196c21f37632e213702995651fd739426b6ee13a (diff) | |
| download | django-rest-framework-6ce5b643fbeab322d85dbaed87d11ffb950c5bed.tar.bz2 | |
Added resourceexample, moved simpleexample to modelresourceexample
Diffstat (limited to 'examples/resourceexample/views.py')
| -rw-r--r-- | examples/resourceexample/views.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py new file mode 100644 index 00000000..650a8e39 --- /dev/null +++ b/examples/resourceexample/views.py @@ -0,0 +1,35 @@ +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.') + + +class ExampleResource(Resource): + """A basic read only resource that points to 3 other resources.""" + allowed_methods = anon_allowed_methods = ('GET',) + + 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 + + def get(self, request, auth, num): + """Handle GET requests""" + if int(num) > 2: + return Response(status.HTTP_404_NOT_FOUND) + return "GET request to AnotherExampleResource %s" % num + + def post(self, request, auth, content, num): + """Handle POST requests""" + if int(num) > 2: + return Response(status.HTTP_404_NOT_FOUND) + return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(content)) |
