Ticket #3652: 6213-choicefield-test-only.patch

File 6213-choicefield-test-only.patch, 1.4 KB (added by Craig Ogg, 17 years ago)

Only the unit test portion of patch against current version of trunk

  • tests/modeltests/model_forms/models.py

     
    7070    def __unicode__(self):
    7171        return self.phone
    7272
     73class Todo(models.Model):
     74    what = models.CharField(maxlength=100)
     75    importance = models.IntegerField(choices=((1, 'Extremely important'), (2,'Floss cat first')), blank=True, null=True)
     76
    7377__test__ = {'API_TESTS': """
    7478>>> from django.newforms import form_for_model, form_for_instance, save_instance, BaseForm, Form, CharField
    7579>>> import datetime
     
    560564True
    561565>>> f.cleaned_data
    562566{'phone': u'312-555-1212', 'description': u'Assistance'}
     567
     568# ChoiceField ############################################################
     569
     570>>> ChoiceForm = form_for_model(Todo)
     571>>> f = ChoiceForm()
     572>>> print f.as_ul()
     573<li><label for="id_what">What:</label> <input id="id_what" type="text" name="what" maxlength="100" /></li>
     574<li><label for="id_importance">Importance:</label> <select name="importance" id="id_importance">
     575<option value="" selected="selected">---------</option>
     576<option value="1">Extremely important</option>
     577<option value="2">Floss cat first</option>
     578</select></li>
     579>>> f = ChoiceForm({'what': 'floss cat', 'importance': ''})
     580>>> f.is_valid()
     581True
     582>>> f.save()
     583<Todo: Todo object>
    563584"""}
Back to Top