Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Refs #15550 -- Corrected another primary-key ordering problem…

… in the modelforms tests. Thanks to bberes for the report.

Backport of r15753 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15754 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 64cf5d33ac0a0bf574ee516366c08ed7e64d469e 1 parent 138c4aa
Russell Keith-Magee freakboy3742 authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 tests/modeltests/model_forms/models.py
21 tests/modeltests/model_forms/models.py
View
@@ -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 @@ class FlexibleDatePost(models.Model):
... 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 @@ class FlexibleDatePost(models.Model):
<select name="parent" id="id_parent">
<option value="">---------</option>
<option value="86" selected="selected">Apple</option>
-<option value="22">Pear</option>
<option value="87">Core</option>
+<option value="22">Pear</option>
</select>
>>> data = model_to_dict(core)
@@ -1571,8 +1574,8 @@ class FlexibleDatePost(models.Model):
>>> for choice in field.choices:
... print choice
(86, u'Apple')
-(22, u'Pear')
(87, u'Core')
+(22, u'Pear')
>>> field.clean([86])
[<Inventory: Apple>]
@@ -1582,7 +1585,7 @@ class FlexibleDatePost(models.Model):
>>> form.is_valid()
True
>>> form.cleaned_data
-{'items': [<Inventory: Pear>, <Inventory: Core>]}
+{'items': [<Inventory: Core>, <Inventory: Pear>]}
# Model field that returns None to exclude itself with explicit fields ########
Please sign in to comment.
Something went wrong with that request. Please try again.