diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-23 12:51:22 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-23 12:51:22 +0000 |
| commit | 5e1a54a3a8285912fed02b2121b53d13fa1061fd (patch) | |
| tree | 7854834beb4dbb639a918a790e5d29d8f5bd502c /tests/regressiontests/forms/models.py | |
| parent | 1e1230c41c428c3909b52720e381cac18942e90e (diff) | |
queryset-refactor: Merged from trunk up to [6595].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6597 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/models.py')
| -rw-r--r-- | tests/regressiontests/forms/models.py | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py index f4f8607193..1a6f566b6b 100644 --- a/tests/regressiontests/forms/models.py +++ b/tests/regressiontests/forms/models.py @@ -1,21 +1,49 @@ +import datetime + from django.db import models -class BoundaryModel(models.Model): +class BoundaryModel(models.Model): positive_integer = models.PositiveIntegerField(null=True, blank=True) - + +class Defaults(models.Model): + name = models.CharField(max_length=256, default='class default value') + def_date = models.DateField(default = datetime.date(1980, 1, 1)) + value = models.IntegerField(default=42) + __test__ = {'API_TESTS': """ ->>> from django.newforms import form_for_model +>>> from django.newforms import form_for_model, form_for_instance # Boundary conditions on a PostitiveIntegerField ######################### ->>> BoundaryForm = form_for_model(BoundaryModel) ->>> f = BoundaryForm({'positive_integer':100}) ->>> f.is_valid() +>>> BoundaryForm = form_for_model(BoundaryModel) +>>> f = BoundaryForm({'positive_integer':100}) +>>> f.is_valid() True ->>> f = BoundaryForm({'positive_integer':0}) ->>> f.is_valid() +>>> f = BoundaryForm({'positive_integer':0}) +>>> f.is_valid() True ->>> f = BoundaryForm({'positive_integer':-100}) ->>> f.is_valid() +>>> f = BoundaryForm({'positive_integer':-100}) +>>> f.is_valid() False -"""}
\ No newline at end of file +# Formfield initial values ######## +If the model has default values for some fields, they are used as the formfield +initial values. +>>> DefaultsForm = form_for_model(Defaults) +>>> DefaultsForm().fields['name'].initial +u'class default value' +>>> DefaultsForm().fields['def_date'].initial +datetime.date(1980, 1, 1) +>>> DefaultsForm().fields['value'].initial +42 + +In form_for_instance(), the initial values come from the instance's values, not +the model's defaults. +>>> foo_instance = Defaults(name=u'instance value', def_date = datetime.date(1969, 4, 4), value = 12) +>>> InstanceForm = form_for_instance(foo_instance) +>>> InstanceForm().fields['name'].initial +u'instance value' +>>> InstanceForm().fields['def_date'].initial +datetime.date(1969, 4, 4) +>>> InstanceForm().fields['value'].initial +12 +"""} |
