Author: kmtracey Date: 2009-02-03 08:24:06 -0600 (Tue, 03 Feb 2009) New Revision: 9811
Modified: django/branches/releases/1.0.X/ django/branches/releases/1.0.X/django/forms/models.py django/branches/releases/1.0.X/tests/modeltests/model_formsets/models.py Log: Fixed #10075: Allowed saving of inline-edited models that use multi-table inheritance. r9809 from trunk. Property changes on: django/branches/releases/1.0.X ___________________________________________________________________ Name: svnmerge-integrated - /django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9783,9789-9790,9793-9795 + /django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9784,9789-9790,9793-9798,9801-9802,9806-9807,9809-9810 Modified: django/branches/releases/1.0.X/django/forms/models.py =================================================================== --- django/branches/releases/1.0.X/django/forms/models.py 2009-02-03 14:19:51 UTC (rev 9810) +++ django/branches/releases/1.0.X/django/forms/models.py 2009-02-03 14:24:06 UTC (rev 9811) @@ -493,7 +493,7 @@ fk_attname = self.fk.get_attname() kwargs = {fk_attname: self.instance.pk} new_obj = self.model(**kwargs) - if fk_attname == self._pk_field.attname: + if fk_attname == self._pk_field.attname or self._pk_field.auto_created: exclude = [self._pk_field.name] else: exclude = [] Modified: django/branches/releases/1.0.X/tests/modeltests/model_formsets/models.py =================================================================== --- django/branches/releases/1.0.X/tests/modeltests/model_formsets/models.py 2009-02-03 14:19:51 UTC (rev 9810) +++ django/branches/releases/1.0.X/tests/modeltests/model_formsets/models.py 2009-02-03 14:24:06 UTC (rev 9811) @@ -36,6 +36,12 @@ 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 @@ ... 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() +<p><label for="id_alternatebook_set-0-title">Title:</label> <input id="id_alternatebook_set-0-title" type="text" name="alternatebook_set-0-title" maxlength="100" /></p> + <p><label for="id_alternatebook_set-0-notes">Notes:</label> <input id="id_alternatebook_set-0-notes" type="text" name="alternatebook_set-0-notes" maxlength="100" /><input type="hidden" name="alternatebook_set-0-author" value="1" id="id_alternatebook_set-0-author" /><input type="hidden" name="alternatebook_set-0-book_ptr" id="id_alternatebook_set-0-book_ptr" /></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() +[<AlternateBook: Flowers of Evil - English translation of Les Fleurs du Mal>] + + # Test a custom primary key ################################################### We need to ensure that it is displayed --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---