Re:Backbone.js and Django
by izak30 on Tuesday July 05, 2011 @07:26PM
(#2731996)
You can directly implement views based on the request method with django's class based views (View) in 1.3.
The dispatch method does almost exactly what your restful function does.
Just inherit from View, and define get(), post(), etc.
Re:Backbone.js and Django
by dikbrouwer on Wednesday July 06, 2011 @01:26AM
(#2732686)
You can replace the toDict() method in your model with the values() method on the default manager. For example: Todo.objects.values('id', 'order', 'content', 'done').get(pk=x)
Just inherit from View, and define get(), post(), etc.
As far as wrappers for backbone and tastypie, I think https://github.com/PaulUithol/backbone-tastypie is a pretty good starting point, and a little more complete than what I wrote there.
Why? See http://django-rest-framework.org/howto/alternativeframeworks...
Also, take a look at the render()[2] shortcut function to collapse the template loading, context settings, and rendering steps into one.
[1]: https://docs.djangoproject.com/en/1.3/ref/request-response/#... [2]: https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/...
return methods[request.method](request, item_id)
with:
return request.method.lower(request, item_id)
https://docs.djangoproject.com/en/dev/topics/signing/
You can use this to store the session data with the user without having to consult a database and without fear that they will tamper with the id:
https://github.com/ericflo/django-cookie-sessions