Permalink
Browse files

install djangorestframework and create the beginnings of the client-s…

…ide models
  • Loading branch information...
1 parent 8a934d0 commit d34a2603d8152c70904f26f1cfdcd37b098e655e @mjumbewu committed Sep 4, 2012
Showing with 36 additions and 0 deletions.
  1. 0 polls_api/__init__.py
  2. +7 −0 polls_api/urls.py
  3. +19 −0 polls_api/views.py
  4. +2 −0 settings.py
  5. +7 −0 static/polls/models.js
  6. +1 −0 urls.py
No changes.
View
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+
+
+urlpatterns = patterns('polls_api.views',
+ url(r'^restframework', include('djangorestframework.urls', namespace='djangorestframework')),
+ url(r'^(?P<poll_id>\d+)/$', 'poll_results_view', name='polls_api_results'),
+)
View
@@ -0,0 +1,19 @@
+from django.shortcuts import get_object_or_404
+from djangorestframework import views
+from polls.models import Poll
+
+class PollResults (views.View):
+
+ def get(self, request, poll_id):
+ poll = get_object_or_404(Poll.objects.all(), pk=poll_id)
+ results = {
+ 'question': poll.question,
+ 'choices': [{
+ 'id': choice.id,
+ 'choice': choice.choice,
+ 'votes': choice.votes
+ } for choice in poll.choice_set.all()]
+ }
+ return results
+
+poll_results_view = PollResults.as_view()
View
@@ -116,6 +116,8 @@
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
+
+ 'djangorestframework',
'polls',
)
@@ -0,0 +1,7 @@
+var Polls = Polls || {};
+
+(function(P, $) {
+
+ P.Results = Backbone.Model.extend({});
+
+})(Polls, jQuery);
View
@@ -12,4 +12,5 @@
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^polls/', include('polls.urls')),
+ (r'^api/', include('polls_api.urls')),
)

0 comments on commit d34a260

Please sign in to comment.