Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tests that make sure we can sort embedded models in lists nicely. Con…

…tributed by Jonas Haag.
  • Loading branch information...
commit 72d399e8e07bef214077bdc2051dafb4c4e21789 1 parent b4464e4
Waldemar Kornewald authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 djangotoolbox/tests.py
View
9 djangotoolbox/tests.py
@@ -48,6 +48,7 @@ class EmbeddedModelFieldModel(models.Model):
typed_list = ListField(EmbeddedModelField('SetModel'))
untyped_list = ListField(EmbeddedModelField())
untyped_dict = DictField(EmbeddedModelField())
+ ordered_list = ListField(EmbeddedModelField(), ordering=lambda obj: obj.index)
class EmbeddedModel(models.Model):
some_relation = models.ForeignKey(DictModel, null=True)
@@ -259,9 +260,13 @@ def test_error_messages(self):
def test_typed_listfield(self):
EmbeddedModelFieldModel.objects.create(
- typed_list=[SetModel(setfield=range(3)), SetModel(setfield=range(9))]
+ typed_list=[SetModel(setfield=range(3)), SetModel(setfield=range(9))],
+ ordered_list=[Target(index=i) for i in xrange(5, 0, -1)]
)
- self.assertIn(5, EmbeddedModelFieldModel.objects.get().typed_list[1].setfield)
+ obj = EmbeddedModelFieldModel.objects.get()
+ self.assertIn(5, obj.typed_list[1].setfield)
+ self.assertEqual([target.index for target in obj.ordered_list],
+ range(1, 6))
def test_untyped_listfield(self):
EmbeddedModelFieldModel.objects.create(untyped_list=[
Please sign in to comment.
Something went wrong with that request. Please try again.