mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[4.0.x] Fixed #33111 -- Fixed passing object to ModelAdmin.get_inlines() when editing in admin change view.
ModelAdmin.get_inlines() should get an unmutated object when creating
formsets during POST request.
Backport of 2f0f30f973 from main
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							881b6bd135
						
					
				
				
					commit
					668b990bf6
				
			| @@ -11,8 +11,9 @@ from .models import ( | ||||
|     Inner4Tabular, Inner5Stacked, Inner5Tabular, NonAutoPKBook, | ||||
|     NonAutoPKBookChild, Novel, NovelReadonlyChapter, OutfitItem, | ||||
|     ParentModelWithCustomPk, Person, Poll, Profile, ProfileCollection, | ||||
|     Question, ReadOnlyInline, ShoppingWeakness, Sighting, SomeChildModel, | ||||
|     SomeParentModel, SottoCapo, Teacher, Title, TitleCollection, | ||||
|     Question, ReadOnlyInline, ShoppingWeakness, ShowInlineChild, | ||||
|     ShowInlineParent, Sighting, SomeChildModel, SomeParentModel, SottoCapo, | ||||
|     Teacher, Title, TitleCollection, | ||||
| ) | ||||
|  | ||||
| site = admin.AdminSite(name="admin") | ||||
| @@ -371,6 +372,17 @@ class ChildHiddenFieldOnSingleLineStackedInline(admin.StackedInline): | ||||
|     fields = ('name', 'position') | ||||
|  | ||||
|  | ||||
| class ShowInlineChildInline(admin.StackedInline): | ||||
|     model = ShowInlineChild | ||||
|  | ||||
|  | ||||
| class ShowInlineParentAdmin(admin.ModelAdmin): | ||||
|     def get_inlines(self, request, obj): | ||||
|         if obj is not None and obj.show_inlines: | ||||
|             return [ShowInlineChildInline] | ||||
|         return [] | ||||
|  | ||||
|  | ||||
| site.register(TitleCollection, inlines=[TitleInline]) | ||||
| # Test bug #12561 and #12778 | ||||
| # only ModelAdmin media | ||||
| @@ -402,6 +414,7 @@ site.register(Course, ClassAdminStackedHorizontal) | ||||
| site.register(CourseProxy, ClassAdminStackedVertical) | ||||
| site.register(CourseProxy1, ClassAdminTabularVertical) | ||||
| site.register(CourseProxy2, ClassAdminTabularHorizontal) | ||||
| site.register(ShowInlineParent, ShowInlineParentAdmin) | ||||
| # Used to test hidden fields in tabular and stacked inlines. | ||||
| site2 = admin.AdminSite(name='tabular_inline_hidden_field_admin') | ||||
| site2.register(SomeParentModel, inlines=[ChildHiddenFieldTabularInline]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user