Changeset 7326 for django/trunk/tests/modeltests/model_forms
- Timestamp:
- 03/19/08 18:10:45 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/modeltests/model_forms/models.py
r7322 r7326 660 660 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] 661 661 662 # check that we can safely iterate choices repeatedly 663 >>> gen_one = list(f.choices) 664 >>> gen_two = f.choices 665 >>> gen_one[2] 666 (2L, u"It's a test") 667 >>> list(gen_two) 668 [(u'', u'---------'), (1L, u'Entertainment'), (2L, u"It's a test"), (3L, u'Third')] 669 670 # check that we can override the label_from_instance method to print custom labels (#4620) 671 >>> f.queryset = Category.objects.all() 672 >>> f.label_from_instance = lambda obj: "category " + str(obj) 673 >>> list(f.choices) 674 [(u'', u'---------'), (1L, 'category Entertainment'), (2L, "category It's a test"), (3L, 'category Third'), (4L, 'category Fourth')] 662 675 663 676 # ModelMultipleChoiceField #################################################### … … 745 758 ValidationError: [u'Select a valid choice. 4 is not one of the available choices.'] 746 759 760 >>> f.queryset = Category.objects.all() 761 >>> f.label_from_instance = lambda obj: "multicategory " + str(obj) 762 >>> list(f.choices) 763 [(1L, 'multicategory Entertainment'), (2L, "multicategory It's a test"), (3L, 'multicategory Third'), (4L, 'multicategory Fourth')] 747 764 748 765 # PhoneNumberField ############################################################
