From 18f42f546a1bb7478829986154375abf37762e13 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 4 Mar 2011 01:27:14 +0000 Subject: [PATCH] Refs #15550 -- Corrected another primary-key ordering problem in the modelforms tests. Thanks to bberes for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15753 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/models.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index d4c915344f..bab0335b8f 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -169,12 +169,15 @@ class ArticleStatus(models.Model): status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True) class Inventory(models.Model): - barcode = models.PositiveIntegerField(unique=True) - parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True) - name = models.CharField(blank=False, max_length=20) + barcode = models.PositiveIntegerField(unique=True) + parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True) + name = models.CharField(blank=False, max_length=20) - def __unicode__(self): - return self.name + class Meta: + ordering = ('name',) + + def __unicode__(self): + return self.name class Book(models.Model): title = models.CharField(max_length=40) @@ -1530,8 +1533,8 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices ... print choice (u'', u'---------') (86, u'Apple') -(22, u'Pear') (87, u'Core') +(22, u'Pear') >>> class InventoryForm(ModelForm): ... class Meta: @@ -1541,8 +1544,8 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices >>> data = model_to_dict(core) @@ -1571,8 +1574,8 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices >>> for choice in field.choices: ... print choice (86, u'Apple') -(22, u'Pear') (87, u'Core') +(22, u'Pear') >>> field.clean([86]) [] @@ -1582,7 +1585,7 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices >>> form.is_valid() True >>> form.cleaned_data -{'items': [, ]} +{'items': [, ]} # Model field that returns None to exclude itself with explicit fields ########