diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-11-30 06:23:24 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-11-30 06:23:24 +0000 |
| commit | c81b01e060ad80a5c4df579a96ff737df2d336b3 (patch) | |
| tree | d34a873e7b5e19f0e91424d4ab28e2f968233d63 /tests/modeltests | |
| parent | f88babafc58eafece72d3f2f7444336c69196808 (diff) | |
newforms-admin: Merged from trunk up to [6775].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6777 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
| -rw-r--r-- | tests/modeltests/field_subclassing/models.py | 10 | ||||
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 73 | ||||
| -rw-r--r-- | tests/modeltests/pagination/models.py | 3 |
3 files changed, 85 insertions, 1 deletions
diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py index 6182266c22..97804f5cd5 100644 --- a/tests/modeltests/field_subclassing/models.py +++ b/tests/modeltests/field_subclassing/models.py @@ -103,4 +103,14 @@ TypeError: Invalid lookup type: 'lt' >>> obj = list(serializers.deserialize("json", stream))[0] >>> obj.object == m True + +# Test retrieving custom field data +>>> m.delete() +>>> m1 = MyModel(name="1", data=Small(1, 2)) +>>> m1.save() +>>> m2 = MyModel(name="2", data=Small(2, 3)) +>>> m2.save() +>>> for m in MyModel.objects.all(): print unicode(m.data) +12 +23 """} diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e4e230c98d..9b0126ff4f 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -30,6 +30,23 @@ ARTICLE_STATUS = ( (3, 'Live'), ) +STEERING_TYPE = ( + ('left', 'Left steering wheel'), + ('right', 'Right steering wheel'), +) + +FUEL_TYPE = ( + ('gas', 'Gasoline'), + ('diesel', 'Diesel'), + ('other', 'Other'), +) + +TRANSMISSION_TYPE = ( + ('at', 'Automatic'), + ('mt', 'Manual'), + ('cvt', 'CVT'), +) + class Category(models.Model): name = models.CharField(max_length=20) slug = models.SlugField(max_length=20) @@ -70,6 +87,12 @@ class PhoneNumber(models.Model): def __unicode__(self): return self.phone +class Car(models.Model): + name = models.CharField(max_length=50) + steering = models.CharField(max_length=5, choices=STEERING_TYPE, default='left') + fuel = models.CharField(max_length=10, choices=FUEL_TYPE) + transmission = models.CharField(max_length=3, choices=TRANSMISSION_TYPE, blank=True, help_text='Leave empty if not applicable.') + __test__ = {'API_TESTS': """ >>> from django.newforms import form_for_model, form_for_instance, save_instance, BaseForm, Form, CharField >>> import datetime @@ -592,4 +615,54 @@ ValidationError: [u'Select a valid choice. 4 is not one of the available choices True >>> f.cleaned_data {'phone': u'312-555-1212', 'description': u'Assistance'} + +# form_for_* blank choices #################################################### + +Show the form for a new Car. Note that steering field doesn't include the blank choice, +because the field is obligatory and has an explicit default. +>>> CarForm = form_for_model(Car) +>>> f = CarForm(auto_id=False) +>>> print f +<tr><th>Name:</th><td><input type="text" name="name" maxlength="50" /></td></tr> +<tr><th>Steering:</th><td><select name="steering"> +<option value="left" selected="selected">Left steering wheel</option> +<option value="right">Right steering wheel</option> +</select></td></tr> +<tr><th>Fuel:</th><td><select name="fuel"> +<option value="" selected="selected">---------</option> +<option value="gas">Gasoline</option> +<option value="diesel">Diesel</option> +<option value="other">Other</option> +</select></td></tr> +<tr><th>Transmission:</th><td><select name="transmission"> +<option value="" selected="selected">---------</option> +<option value="at">Automatic</option> +<option value="mt">Manual</option> +<option value="cvt">CVT</option> +</select><br />Leave empty if not applicable.</td></tr> + +Create a Car, and display the form for modifying it. Note that now the fuel +selector doesn't include the blank choice as well, since the field is +obligatory and can not be changed to be blank. +>>> honda = Car(name='Honda Accord Wagon', steering='right', fuel='gas', transmission='at') +>>> honda.save() +>>> HondaForm = form_for_instance(honda) +>>> f = HondaForm(auto_id=False) +>>> print f +<tr><th>Name:</th><td><input type="text" name="name" value="Honda Accord Wagon" maxlength="50" /></td></tr> +<tr><th>Steering:</th><td><select name="steering"> +<option value="left">Left steering wheel</option> +<option value="right" selected="selected">Right steering wheel</option> +</select></td></tr> +<tr><th>Fuel:</th><td><select name="fuel"> +<option value="gas" selected="selected">Gasoline</option> +<option value="diesel">Diesel</option> +<option value="other">Other</option> +</select></td></tr> +<tr><th>Transmission:</th><td><select name="transmission"> +<option value="">---------</option> +<option value="at" selected="selected">Automatic</option> +<option value="mt">Manual</option> +<option value="cvt">CVT</option> +</select><br />Leave empty if not applicable.</td></tr> """} diff --git a/tests/modeltests/pagination/models.py b/tests/modeltests/pagination/models.py index 1dcec00a32..f44c67a139 100644 --- a/tests/modeltests/pagination/models.py +++ b/tests/modeltests/pagination/models.py @@ -78,7 +78,8 @@ True >>> paginator.pages 2 -# The paginator can provide a list of all available pages +# The paginator can provide a list of all available pages. +>>> paginator = ObjectPaginator(Article.objects.all(), 10) >>> paginator.page_range [1, 2] """} |
