The QDjangoScript class makes it easy to access your models from QtScript.
Making your models scriptable
You can register a model with a QScriptEngine instance as follows:
#include <QDjangoQuerySet.h>
#include <QDjangoScript.h>
QScriptEngine *engine = new QScriptEngine;
Using your models from a script
Because QDjango makes use of Qt's property system, all model fields can automatically be accessed from QtScript. For instance if you declared a User
model, you can run the following code:
user = new User();
user.username = "someuser";
user.password = "somepassword";
user.save();
user.remove();
You can also perform database queries:
qs = User.objects.filter({'username': 'foouser', 'password': 'foopass'});
for (var i = 0; i < qs.size(); i++) {
user = qs.at(i);
print("found " + user.username);
}
qs.remove();