From 81ae2afdec8a81b94bacf02a1242277e0b4caceb Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Tue, 3 Feb 2009 14:02:09 +0000 Subject: Fixed 10075: Allowed saving of inline-edited models that use multi-table inheritance. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9809 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_formsets/models.py | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py index f11d4538ef..0503ea2a84 100644 --- a/tests/modeltests/model_formsets/models.py +++ b/tests/modeltests/model_formsets/models.py @@ -36,6 +36,12 @@ class BookWithCustomPK(models.Model): def __unicode__(self): return u'%s: %s' % (self.my_pk, self.title) +class AlternateBook(Book): + notes = models.CharField(max_length=100) + + def __unicode__(self): + return u'%s - %s' % (self.title, self.notes) + class AuthorMeeting(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author) @@ -520,6 +526,33 @@ True ... print book.title Les Fleurs du Mal +Test inline formsets where the inline-edited object uses multi-table inheritance, thus +has a non AutoField yet auto-created primary key. + +>>> AuthorBooksFormSet3 = inlineformset_factory(Author, AlternateBook, can_delete=False, extra=1) + +>>> formset = AuthorBooksFormSet3(instance=author) +>>> for form in formset.forms: +... print form.as_p() +

+

+ + +>>> data = { +... 'alternatebook_set-TOTAL_FORMS': '1', # the number of forms rendered +... 'alternatebook_set-INITIAL_FORMS': '0', # the number of forms with initial data +... 'alternatebook_set-0-title': 'Flowers of Evil', +... 'alternatebook_set-0-notes': 'English translation of Les Fleurs du Mal' +... } + +>>> formset = AuthorBooksFormSet3(data, instance=author) +>>> formset.is_valid() +True + +>>> formset.save() +[] + + # Test a custom primary key ################################################### We need to ensure that it is displayed -- cgit v1.3