Creating JavaScript objects from Django models

I do a lot of JavaScript work in the browser and would like to have some backend functionality in the interface. In particular, it would be nice to have a function get(), save(), all()and count()are available to the client. In addition, it would be great to have a list of model fields already available in the generated JavaScript object.

Whether the current user can read or write records is a separate issue, I will deal with the use of Django authentication. Currently, the search will be the beginning.

In short, is there any code that will generate a JavaScript model from a Django model?

Thanks.

+5
source share
5 answers

It looks like you are looking for a complete JavaScript interface for model and query APIs. I cannot imagine that this would ever be done, or even be a simple task. Not only do you need to somehow generate JavaScript instances for the models (much more than JSON serialization, since you also need methods), but you will need to open a web service that can handle all kinds of DB-API calls. I can’t even imagine where to start, and the security problems can be too numerous to easily overcome.

( ) Django REST JSON. AJAX GET , , . JSON . JavaScript AJAX POST . , , - JavaScript HTML .

+7
+1

, , , , . github_bumby_jslib.
get(), . :)

jslib - Django, AJAX Django.

+1

, JSON . . JSON.org.

0

So, it has been a while since I posted the original question, and a number of events have happened since then in Djangoland. Last but not least, it is a small library called the Django REST Framework. I will use it in a new project, and it looks pretty cool.

http://www.django-rest-framework.org

0
source

All Articles