| 1 |
from optparse import OptionParser |
|---|
| 2 |
import sys |
|---|
| 3 |
|
|---|
| 4 |
p = OptionParser() |
|---|
| 5 |
|
|---|
| 6 |
p.add_option("-a", "--app", dest="app", help="The app which contains the model") |
|---|
| 7 |
p.add_option("-m", "--model", dest="model", help="The model to produce the form for") |
|---|
| 8 |
|
|---|
| 9 |
options, args = p.parse_args() |
|---|
| 10 |
|
|---|
| 11 |
if not (options.model and options.app): |
|---|
| 12 |
sys.exit() |
|---|
| 13 |
|
|---|
| 14 |
m = __import__("django.models.%s" % (options.app,), '', '', [options.model]) |
|---|
| 15 |
|
|---|
| 16 |
a = getattr(m, options.model) |
|---|
| 17 |
|
|---|
| 18 |
print '<form method="POST" action=".">' |
|---|
| 19 |
|
|---|
| 20 |
for field in [f for f in a._meta.fields if f.name !='id']: |
|---|
| 21 |
print "<p>" |
|---|
| 22 |
print "<label for=\"id_%s\">%s:</label> {{ form.name }}" % (field.name, field.verbose_name and field.verbose_name or field.name,) |
|---|
| 23 |
print "{%% if form.name.errors %%}*** {{ form.name.errors|join:", " }}{%% endif %%}" |
|---|
| 24 |
print "</p>" |
|---|
| 25 |
|
|---|
| 26 |
print '<input type="submit" value="submit" />' |
|---|
| 27 |
print '</form>' |
|---|