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
This commit is contained in:
Russell Keith-Magee 2011-03-04 01:27:14 +00:00
parent 90564a156c
commit 18f42f546a
1 changed files with 12 additions and 9 deletions

View File

@ -169,12 +169,15 @@ class ArticleStatus(models.Model):
status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True) status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)
class Inventory(models.Model): class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True) barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True) parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
name = models.CharField(blank=False, max_length=20) name = models.CharField(blank=False, max_length=20)
def __unicode__(self): class Meta:
return self.name ordering = ('name',)
def __unicode__(self):
return self.name
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=40) 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 ... print choice
(u'', u'---------') (u'', u'---------')
(86, u'Apple') (86, u'Apple')
(22, u'Pear')
(87, u'Core') (87, u'Core')
(22, u'Pear')
>>> class InventoryForm(ModelForm): >>> class InventoryForm(ModelForm):
... class Meta: ... class Meta:
@ -1541,8 +1544,8 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices
<select name="parent" id="id_parent"> <select name="parent" id="id_parent">
<option value="">---------</option> <option value="">---------</option>
<option value="86" selected="selected">Apple</option> <option value="86" selected="selected">Apple</option>
<option value="22">Pear</option>
<option value="87">Core</option> <option value="87">Core</option>
<option value="22">Pear</option>
</select> </select>
>>> data = model_to_dict(core) >>> 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: >>> for choice in field.choices:
... print choice ... print choice
(86, u'Apple') (86, u'Apple')
(22, u'Pear')
(87, u'Core') (87, u'Core')
(22, u'Pear')
>>> field.clean([86]) >>> field.clean([86])
[<Inventory: Apple>] [<Inventory: Apple>]
@ -1582,7 +1585,7 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices
>>> form.is_valid() >>> form.is_valid()
True True
>>> form.cleaned_data >>> form.cleaned_data
{'items': [<Inventory: Pear>, <Inventory: Core>]} {'items': [<Inventory: Core>, <Inventory: Pear>]}
# Model field that returns None to exclude itself with explicit fields ######## # Model field that returns None to exclude itself with explicit fields ########