|
GettingStarted
Getting started with dynamic Django dataforms.
Featured Instant ExampleTo see django-dataforms in action, download the source, then go into the example folder and run ./manage.py runserver. Now visit your server and you'll see the dynamically created form. You can also see the data needed to create this form in the administration interface. This is a single dynamic form which will create Answers in the database when you submit the form. Creating your own custom database-driven formsAdd the transaction middlewareTo maintain data integrity, you'll need to add the transaction middleware to your settings.py. This will put all queries from each request into a single transaction—so if something goes wrong, all DB changes from the entire request will not be committed. MIDDLEWARE_CLASSES = ( # ... 'django.middleware.transaction.TransactionMiddleware', ) Import static filesCopy example/static/scripts/jquery.adminmenusort.js and example/static/scripts/bindings.js to a subdirectory of your MEDIA_URL named scripts. So, for example, if your MEDIA_URL was /static, then you should copy the file to the folder that serves /static/scripts/jquery.adminmenusort.js Create your form definitionNow, create the definition of your form using the Django admin, creating a dataform and associating the correct fields and choices to fields. WRITEME BindingsDjango-dataforms has built-in support for field bindings (If the user checks "yes" on a field, show another field or fields.) The bindings just need to be defined in the admin when creating your form definition. WRITEME Use the form on a pageIn a view, you simply have to call create_form and pass the submission string from dataforms.forms import create_form def view_function(request): form = create_form(request=request, form='personal-information', submission="myForm") if request.method == "POST": if form.is_valid(): form.save() Let's look at the arguments to create_form:
If form.save() is called on a bound form object (a form that is already tied to a Submission), the submitted data will be overwritten in the database allowing for easy editing of previously submitted form data. |
Do you know if this app would work on Google's App Engine?
mark.ellul: That's a good question; I do not think that django-dataforms will work without some heavy modification to take advantage of the App Engine backend data store. From http://code.google.com/appengine/articles/django.html it looks like "App Engine does not support Django models," so our models would need to be re-written for App Engine. http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html
If anyone is interested in doing this, I'd be happy to work with you on integrating any code that's needed.