1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from django.conf import settings
import random
class DebugForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(DebugForm, self).__init__(*args, **kwargs)
if kwargs.get('instance'):
return
if settings.DEBUG:
for field in self.DEBUG_DATA.keys():
val = random.choice(self.DEBUG_DATA[field])
self.fields[field].initial = val
class MyForm(DebugForm):
DEBUG_DATA = {
'comment':['this is some sample data', 'this is some more sample data']
}
class Meta:
model = YourModel
|
More like this
- Complex Formsets, Redux by smagala 3 years, 2 months ago
- ReportBug() (exception emails - ala django debug style) by sleepycal 2 years, 8 months ago
- RadioSelectWithHelpText by moxypark 2 years, 9 months ago
- ByteSplitterField by Lacour 1 year, 8 months ago
- Complex Formsets by smagala 4 years, 3 months ago
Comments
Haven't tried it out, but that looks pretty cool. I've always just filled the form out once, recorded it with Molybdenum, and then "replayed" the form each time there after.
I'll definitely have to give this a whirl. :D
#
And I'll have to take a look at Molybdenum :)
#