Scaffold Script
Looks like this uses old Forms, and is replaced by FormGenScript
We all know that "Every form is different" but sometimes they're quite similar. This script takes the names of an app and a model and spews out a simple set of form fields which you can then change as appropriate.
Usage is simple. Save the script next to manage.py in your project's directory and do something like this: ./scaffold.py -a ToDo -m Category
This is an interesting script to combine with ManipulatorScript
Enjoy
Example
From this:
class Category(meta.Model): category = meta.CharField(maxlength=50, unique=True) createdOn = meta.DateField(auto_now_add=True) modifiedOn = meta.DateField(auto_now=True) test = meta.ManyToManyField(auth.User, verbose_name='This is a test field', related_name='test') test2 = meta.OneToOneField(auth.User, verbose_name='test2', related_name='test2') def __repr__(self): return "%s" % (self.category,) class META: admin = meta.Admin()
To this:
<form method="POST" action="."> <p> <label for="id_category">category:</label> {{ form.category }} {% if form.category.errors %} *** {{ form.category.errors|join:", " }} {% endif %} </p> <p> <label for="id_createdOn">createdOn:</label> {{ form.createdOn }} {% if form.createdOn.errors %} *** {{ form.createdOn.errors|join:", " }} {% endif %} </p> <p> <label for="id_modifiedOn">modifiedOn:</label> {{ form.modifiedOn }} {% if form.modifiedOn.errors %} *** {{ form.modifiedOn.errors|join:", " }} {% endif %} </p> <p> <label for="id_test2">test2:</label> {{ form.test2 }} {% if form.test2.errors %} *** {{ form.test2.errors|join:", " }} {% endif %} </p> <p> <label for="id_test">This is a test field:</label> {{ form.test }} {% if form.test.errors %} *** {{ form.test.errors|join:", " }} {% endif %} </p> <input type="submit" value="submit" /> </form>
TODO: shebang line should probably be #!/usr/bin/env python as in manage.py etc.
Attachments
- scaffold.py (0.8 kB) -
The script
, added by Lllama on 02/25/06 11:05:25. - scaffold.2.py (1.2 kB) -
bugfixes and datetime support
, added by akaihola on 02/25/06 16:41:44. - scaffold.3.py (1.9 kB) -
Sets environment settings if you run it in your project directory. Now handles image files.
, added by Lllama on 02/26/06 06:58:43. - scaffold.4.py (2.3 kB) -
Adds in M2M fields
, added by Lllama on 03/16/06 03:42:05. - scaffold_mr.py (2.3 kB) -
Updated for the magic_removal branch
, added by davidwarry@aol.com on 03/16/06 23:22:24. - scaffold_mr2.py (2.3 kB) -
Fixed a syntax error in the magic-removal version.
, added by nate-django@refried.org on 08/22/06 21:40:14.
