Ticket #16838: t16838-potential_fix.diff
File t16838-potential_fix.diff, 6.1 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 2825c99..f05b5cb 100644
a b class ModelAdmin(BaseModelAdmin): 926 926 for FormSet, inline in zip(self.get_formsets(request), self.inline_instances): 927 927 prefix = FormSet.get_default_prefix() 928 928 prefixes[prefix] = prefixes.get(prefix, 0) + 1 929 if prefixes[prefix] != 1 :929 if prefixes[prefix] != 1 or not prefix: 930 930 prefix = "%s-%s" % (prefix, prefixes[prefix]) 931 931 formset = FormSet(data=request.POST, files=request.FILES, 932 932 instance=new_object, … … class ModelAdmin(BaseModelAdmin): 955 955 self.inline_instances): 956 956 prefix = FormSet.get_default_prefix() 957 957 prefixes[prefix] = prefixes.get(prefix, 0) + 1 958 if prefixes[prefix] != 1 :958 if prefixes[prefix] != 1 or not prefix: 959 959 prefix = "%s-%s" % (prefix, prefixes[prefix]) 960 960 formset = FormSet(instance=self.model(), prefix=prefix, 961 961 queryset=inline.queryset(request)) … … class ModelAdmin(BaseModelAdmin): 1025 1025 self.inline_instances): 1026 1026 prefix = FormSet.get_default_prefix() 1027 1027 prefixes[prefix] = prefixes.get(prefix, 0) + 1 1028 if prefixes[prefix] != 1 :1028 if prefixes[prefix] != 1 or not prefix: 1029 1029 prefix = "%s-%s" % (prefix, prefixes[prefix]) 1030 1030 formset = FormSet(request.POST, request.FILES, 1031 1031 instance=new_object, prefix=prefix, … … class ModelAdmin(BaseModelAdmin): 1046 1046 for FormSet, inline in zip(self.get_formsets(request, obj), self.inline_instances): 1047 1047 prefix = FormSet.get_default_prefix() 1048 1048 prefixes[prefix] = prefixes.get(prefix, 0) + 1 1049 if prefixes[prefix] != 1 :1049 if prefixes[prefix] != 1 or not prefix: 1050 1050 prefix = "%s-%s" % (prefix, prefixes[prefix]) 1051 1051 formset = FormSet(instance=obj, prefix=prefix, 1052 1052 queryset=inline.queryset(request)) -
tests/regressiontests/admin_inlines/admin.py
diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py index 6f8076a..4edd361 100644
a b class NovelAdmin(admin.ModelAdmin): 101 101 inlines = [ChapterInline] 102 102 103 103 104 class ConsigliereInline(admin.TabularInline): 105 model = Consigliere 106 107 108 class SottoCapoInline(admin.TabularInline): 109 model = SottoCapo 110 111 104 112 site.register(TitleCollection, inlines=[TitleInline]) 105 113 # Test bug #12561 and #12778 106 114 # only ModelAdmin media … … site.register(Novel, NovelAdmin) 115 123 site.register(Fashionista, inlines=[InlineWeakness]) 116 124 site.register(Holder4, Holder4Admin) 117 125 site.register(Author, AuthorAdmin) 126 site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline]) -
tests/regressiontests/admin_inlines/models.py
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index f4e58f2..748280d 100644
a b class Novel(models.Model): 122 122 class Chapter(models.Model): 123 123 novel = models.ForeignKey(Novel) 124 124 125 126 # Models for #16838 127 class CapoFamiglia(models.Model): 128 name = models.CharField(max_length=100) 129 130 131 class Consigliere(models.Model): 132 name = models.CharField(max_length=100) 133 capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+') 134 135 136 class SottoCapo(models.Model): 137 name = models.CharField(max_length=100) 138 capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+') -
tests/regressiontests/admin_inlines/tests.py
diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index efa6cf6..955d620 100644
a b from django.test import TestCase 4 4 5 5 # local test models 6 6 from models import (Holder, Inner, Holder2, Inner2, Holder3, 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child) 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child, 8 CapoFamiglia, Consigliere, SottoCapo) 8 9 from admin import InnerInline 9 10 10 11 … … class TestInline(TestCase): 115 116 self.assertContains(response, '<p class="help">Awesome stacked help text is awesome.</p>', 4) 116 117 self.assertContains(response, '<img src="/static/admin/img/icon-unknown.gif" class="help help-tooltip" width="10" height="10" alt="(Awesome tabular help text is awesome.)" title="Awesome tabular help text is awesome." />', 1) 117 118 119 def test_non_related_name_inline(self): 120 """ 121 Ensure that multiple inlines with related_name='+' have correct form 122 prefixes. Bug #16838. 123 """ 124 response = self.client.get('/admin/admin_inlines/capofamiglia/add/') 125 126 self.assertContains(response, 127 '<input type="hidden" name="-1-0-id" id="id_-1-0-id" />') 128 self.assertContains(response, 129 '<input type="hidden" name="-1-0-capo_famiglia" ' 130 'id="id_-1-0-capo_famiglia" />') 131 self.assertContains(response, 132 '<input id="id_-1-0-name" type="text" class="vTextField" ' 133 'name="-1-0-name" maxlength="100" />') 134 135 self.assertContains(response, 136 '<input type="hidden" name="-2-0-id" id="id_-2-0-id" />') 137 self.assertContains(response, 138 '<input type="hidden" name="-2-0-capo_famiglia" ' 139 'id="id_-2-0-capo_famiglia" />') 140 self.assertContains(response, 141 '<input id="id_-2-0-name" type="text" class="vTextField" ' 142 'name="-2-0-name" maxlength="100" />') 143 144 118 145 class TestInlineMedia(TestCase): 119 146 urls = "regressiontests.admin_inlines.urls" 120 147 fixtures = ['admin-views-users.xml']