summaryrefslogtreecommitdiff
path: root/tests/model_formsets
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-01-26 18:23:10 +0100
committerClaude Paroz <claude@2xlibre.net>2013-03-01 09:35:18 +0100
commit3318595c0bfeda9f6bae8aa11dda68647ae55fde (patch)
treee64dbdd8c78310df26937a87a2111b3dcc11074e /tests/model_formsets
parent892bc91cb0036d6868081363628f65094c4790d6 (diff)
Fixed #18898 -- Added tests with a fix for ModelMultipleChoiceField
Diffstat (limited to 'tests/model_formsets')
-rw-r--r--tests/model_formsets/tests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py
index 037163b741..c48f88ded8 100644
--- a/tests/model_formsets/tests.py
+++ b/tests/model_formsets/tests.py
@@ -1071,6 +1071,38 @@ class ModelFormsetTest(TestCase):
FormSet = modelformset_factory(ClassyMexicanRestaurant, fields=["tacos_are_yummy"])
self.assertEqual(sorted(FormSet().forms[0].fields.keys()), ['restaurant', 'tacos_are_yummy'])
+ def test_model_formset_with_initial_model_instance(self):
+ # has_changed should compare model instance and primary key
+ # see #18898
+ FormSet = modelformset_factory(Poem)
+ john_milton = Poet(name="John Milton")
+ john_milton.save()
+ data = {
+ 'form-TOTAL_FORMS': 1,
+ 'form-INITIAL_FORMS': 0,
+ 'form-MAX_NUM_FORMS': '',
+ 'form-0-name': '',
+ 'form-0-poet': str(john_milton.id),
+ }
+ formset = FormSet(initial=[{'poet': john_milton}], data=data)
+ self.assertFalse(formset.extra_forms[0].has_changed())
+
+ def test_model_formset_with_initial_queryset(self):
+ # has_changed should work with queryset and list of pk's
+ # see #18898
+ FormSet = modelformset_factory(AuthorMeeting)
+ author = Author.objects.create(pk=1, name='Charles Baudelaire')
+ data = {
+ 'form-TOTAL_FORMS': 1,
+ 'form-INITIAL_FORMS': 0,
+ 'form-MAX_NUM_FORMS': '',
+ 'form-0-name': '',
+ 'form-0-created': '',
+ 'form-0-authors': list(Author.objects.values_list('id', flat=True)),
+ }
+ formset = FormSet(initial=[{'authors': Author.objects.all()}], data=data)
+ self.assertFalse(formset.extra_forms[0].has_changed())
+
def test_prevent_duplicates_from_with_the_same_formset(self):
FormSet = modelformset_factory(Product, extra=2)
data = {