Reid van Melle avatar Reid van Melle committed 62ce1f7

made the handler return the choice as well

Comments (0)

Files changed (3)

 - https://bitbucket.org/jespern/django-piston/wiki/Documentation#!getting-started
 - http://kencochrane.net/blog/2011/04/deploying-my-django-application-to-dotcloud/
 
+Was building some of the basic models etc. from here:
+
+- http://docs.djangoproject.com/en/dev/intro/tutorial03/?from=olddocs
+
 === Some initial standard setup ===
 
 $ dotcloud create <project>
 
 # OK, let's take this baby for a spin
  
-$ curl http://localhost:8000/api/polls
+$ curl curl http://www.<project>.dotcloud.com/api/polls
 Authorization Required
-$ curl --user <username>:<password> http://localhost:8000/api/polls
+$ curl --user <username>:<password> http://www.<project>.dotcloud.com/api/polls
 [
     {
-        "question": "This is a great question"
+        "question": "This is a great question", 
+        "choices": [
+            {
+                "votes": 5, 
+                "choice": "choice 1"
+            }, 
+            {
+                "votes": 2, 
+                "choice": "Choice 2"
+            }
+        ]
     }
 ]

www/api/handlers.py

 
 class PollHandler(BaseHandler):
     allowed_methods = ('GET', 'PUT', 'DELETE')
-    fields = ('question',)
+    fields = ('question', ('choices', ('choice', 'votes')))
     exclude = ('id', re.compile(r'^private_'))
     model = Poll
 

www/myapp/models.py

     pub_date = models.DateTimeField('date published')
 
 class Choice(models.Model):
-    poll = models.ForeignKey(Poll)
+    poll = models.ForeignKey(Poll, related_name='choices')
     choice = models.CharField(max_length=200)
     votes = models.IntegerField()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.