mirror of
				https://github.com/django/django.git
				synced 2025-10-29 00:26:07 +00:00 
			
		
		
		
	[3.2.x] Fixed #18549 -- Fixed heading for inlines with a OneToOneField.
Used verbose_name instead of verbose_name_plural.
Backport of 0aff3fd711 from master.
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							3dc3a952b2
						
					
				
				
					commit
					a91bf80459
				
			| @@ -4,7 +4,11 @@ | ||||
|      data-inline-type="stacked" | ||||
|      data-inline-formset="{{ inline_admin_formset.inline_formset_data }}"> | ||||
| <fieldset class="module {{ inline_admin_formset.classes }}"> | ||||
|   <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2> | ||||
|   {% if inline_admin_formset.formset.max_num == 1 %} | ||||
|     <h2>{{ inline_admin_formset.opts.verbose_name|capfirst }}</h2> | ||||
|   {% else %} | ||||
|     <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2> | ||||
|   {% endif %} | ||||
| {{ inline_admin_formset.formset.management_form }} | ||||
| {{ inline_admin_formset.formset.non_form_errors }} | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,11 @@ | ||||
|   <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}"> | ||||
| {{ inline_admin_formset.formset.management_form }} | ||||
| <fieldset class="module {{ inline_admin_formset.classes }}"> | ||||
|    <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2> | ||||
|    {% if inline_admin_formset.formset.max_num == 1 %} | ||||
|      <h2>{{ inline_admin_formset.opts.verbose_name|capfirst }}</h2> | ||||
|    {% else %} | ||||
|      <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2> | ||||
|    {% endif %} | ||||
|    {{ inline_admin_formset.formset.non_form_errors }} | ||||
|    <table> | ||||
|      <thead><tr> | ||||
|   | ||||
| @@ -9,8 +9,8 @@ from .models import ( | ||||
|     Holder, Holder2, Holder3, Holder4, Holder5, Inner, Inner2, Inner3, | ||||
|     Inner4Stacked, Inner4Tabular, Inner5Stacked, Inner5Tabular, NonAutoPKBook, | ||||
|     NonAutoPKBookChild, Novel, NovelReadonlyChapter, OutfitItem, | ||||
|     ParentModelWithCustomPk, Poll, Profile, ProfileCollection, Question, | ||||
|     ReadOnlyInline, ShoppingWeakness, Sighting, SomeChildModel, | ||||
|     ParentModelWithCustomPk, Person, Poll, Profile, ProfileCollection, | ||||
|     Question, ReadOnlyInline, ShoppingWeakness, Sighting, SomeChildModel, | ||||
|     SomeParentModel, SottoCapo, Teacher, Title, TitleCollection, | ||||
| ) | ||||
|  | ||||
| @@ -292,6 +292,14 @@ class TeacherAdmin(admin.ModelAdmin): | ||||
|     inlines = [StudentInline] | ||||
|  | ||||
|  | ||||
| class AuthorTabularInline(admin.TabularInline): | ||||
|     model = Author | ||||
|  | ||||
|  | ||||
| class FashonistaStackedInline(admin.StackedInline): | ||||
|     model = Fashionista | ||||
|  | ||||
|  | ||||
| site.register(TitleCollection, inlines=[TitleInline]) | ||||
| # Test bug #12561 and #12778 | ||||
| # only ModelAdmin media | ||||
| @@ -318,3 +326,4 @@ site.register([Question, Inner4Stacked, Inner4Tabular]) | ||||
| site.register(Teacher, TeacherAdmin) | ||||
| site.register(Chapter, inlines=[FootNoteNonEditableInlineCustomForm]) | ||||
| site.register(OutfitItem, inlines=[WeaknessInlineCustomForm]) | ||||
| site.register(Person, inlines=[AuthorTabularInline, FashonistaStackedInline]) | ||||
|   | ||||
| @@ -44,6 +44,7 @@ class Book(models.Model): | ||||
| class Author(models.Model): | ||||
|     name = models.CharField(max_length=50) | ||||
|     books = models.ManyToManyField(Book) | ||||
|     person = models.OneToOneField('Person', models.CASCADE, null=True) | ||||
|  | ||||
|  | ||||
| class NonAutoPKBook(models.Model): | ||||
|   | ||||
| @@ -480,6 +480,11 @@ class TestInline(TestDataMixin, TestCase): | ||||
|             html=True | ||||
|         ) | ||||
|  | ||||
|     def test_inlines_singular_heading_one_to_one(self): | ||||
|         response = self.client.get(reverse('admin:admin_inlines_person_add')) | ||||
|         self.assertContains(response, '<h2>Author</h2>', html=True)  # Tabular. | ||||
|         self.assertContains(response, '<h2>Fashionista</h2>', html=True)  # Stacked. | ||||
|  | ||||
|  | ||||
| @override_settings(ROOT_URLCONF='admin_inlines.urls') | ||||
| class TestInlineMedia(TestDataMixin, TestCase): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user