Permalink
Browse files

bootstrap data in to the details page

  • Loading branch information...
1 parent bdb7f36 commit a58d8b1136508387d74b8d0f3014e6f8cbc75262 @mjumbewu committed Sep 4, 2012
Showing with 6 additions and 1 deletion.
  1. +5 −0 polls/views.py
  2. +1 −1 templates/polls/detail.html
View
@@ -1,9 +1,11 @@
+import json
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from polls.forms import PollForm
from polls.models import Poll, Choice
+from polls_api.resources import PollResource
def index(request):
@@ -23,9 +25,12 @@ def detail(request, poll_id):
else:
form = PollForm(instance=p)
+ initial_results_data = PollResource().serialize(p)
+
return render_to_response('polls/detail.html', {
'poll': p,
'form': form,
+ 'initial_results_data': json.dumps(initial_results_data)
}, context_instance=RequestContext(request))
@@ -12,7 +12,7 @@
</form>
<script>
- results = new Polls.Results();
+ results = new Polls.Results({{ initial_results_data|default:'{}'|safe }});
results.url = '{% url polls_api_results poll.id %}';
</script>

0 comments on commit a58d8b1

Please sign in to comment.