aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/examples/blogpost.rst2
-rw-r--r--docs/examples/objectstore.rst2
-rw-r--r--docs/index.rst37
-rw-r--r--examples/simpleexample/models.py4
-rw-r--r--examples/simpleexample/urls.py2
5 files changed, 43 insertions, 4 deletions
diff --git a/docs/examples/blogpost.rst b/docs/examples/blogpost.rst
index 067a6bb3..aeb3d2fd 100644
--- a/docs/examples/blogpost.rst
+++ b/docs/examples/blogpost.rst
@@ -1,6 +1,8 @@
ModelResource example - Blog posts
==================================
+* http://api.django-rest-framework.org/blog-post/
+
The models
----------
diff --git a/docs/examples/objectstore.rst b/docs/examples/objectstore.rst
index be65a3b7..05c750c5 100644
--- a/docs/examples/objectstore.rst
+++ b/docs/examples/objectstore.rst
@@ -1,6 +1,8 @@
Resource example - An object store
==================================
+* http://api.django-rest-framework.org/object-store/
+
``urls.py``
.. include:: ../../examples/objectstore/urls.py
diff --git a/docs/index.rst b/docs/index.rst
index 7da3f017..8b273dd7 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -41,7 +41,26 @@ Getting Started
---------------
Often you'll want parts of your API to directly map to existing Models.
-At it's simplest this looks something like this...
+Typically that might look this looks something like this...
+
+``models.py``
+
+.. code-block:: python
+
+ from django.db import models
+
+ class MyModel(models.Model):
+ foo = models.BooleanField()
+ bar = models.IntegerField(help_text='Must be an integer.')
+ baz = models.CharField(max_length=32, help_text='Free text. Max length 32 chars.')
+ created = models.DateTimeField(auto_now_add=True)
+
+ class Meta:
+ ordering = ('created',)
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('simpleexample.views.MyModelResource', (self.pk,))
``urls.py``
@@ -53,6 +72,22 @@ At it's simplest this looks something like this...
.. include:: ../examples/simpleexample/views.py
:literal:
+And we're done. We've now got a fully browseable API, which supports multiple input and output media types, and has all the nice automatic field validation that Django gives us for free.
+
+We can visit the API in our browser:
+
+* http://api.django-rest-framework.org/simple-example/
+
+Or access it from the command line using curl:
+
+.. code-block:: bash
+
+ bash: curl -X POST -H 'X-Requested-With: XMLHttpRequest' --data 'foo=bar' http://api.django-rest-framework.org/simple-example/
+ {"detail": {"bar": ["This field is required."], "baz": ["This field is required."]}}
+
+.. note::
+
+ TODO: Mention adding custom handler methods, but that the defaults will often do what we want already. Document a Resource example, not tied to models.
Examples
--------
diff --git a/examples/simpleexample/models.py b/examples/simpleexample/models.py
index 13867f61..b628f895 100644
--- a/examples/simpleexample/models.py
+++ b/examples/simpleexample/models.py
@@ -1,6 +1,6 @@
from django.db import models
-MAX_INSTANCES = 20
+MAX_INSTANCES = 10
class MyModel(models.Model):
foo = models.BooleanField()
@@ -13,9 +13,9 @@ class MyModel(models.Model):
def save(self, *args, **kwargs):
"""For the purposes of the sandbox, limit the maximum number of stored models."""
+ super(MyModel, self).save(*args, **kwargs)
while MyModel.objects.all().count() > MAX_INSTANCES:
MyModel.objects.all()[0].delete()
- super(MyModel, self).save(*args, **kwargs)
@models.permalink
def get_absolute_url(self):
diff --git a/examples/simpleexample/urls.py b/examples/simpleexample/urls.py
index d853ba5a..92e782dc 100644
--- a/examples/simpleexample/urls.py
+++ b/examples/simpleexample/urls.py
@@ -1,6 +1,6 @@
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('simpleexample.views',
- url(r'^$', 'MyModelRootResource'),
+ url(r'^$', 'MyModelRootResource'),
url(r'^([0-9]+)/$', 'MyModelResource'),
)