mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.6.x] Fixed #21129 -- Prevented admin filter params modifications from throwing an exception.
Thanks Tuttle for the report.
Backport of 5381317fe3 from master
			
			
This commit is contained in:
		| @@ -306,6 +306,10 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)): | |||||||
|                 # later. |                 # later. | ||||||
|                 return True |                 return True | ||||||
|             if hasattr(field, 'rel'): |             if hasattr(field, 'rel'): | ||||||
|  |                 if field.rel is None: | ||||||
|  |                     # This property or relation doesn't exist, but it's allowed | ||||||
|  |                     # since it's ignored in ChangeList.get_filters(). | ||||||
|  |                     return True | ||||||
|                 model = field.rel.to |                 model = field.rel.to | ||||||
|                 rel_name = field.rel.get_related_field().name |                 rel_name = field.rel.get_related_field().name | ||||||
|             elif isinstance(field, RelatedObject): |             elif isinstance(field, RelatedObject): | ||||||
|   | |||||||
| @@ -88,6 +88,18 @@ class ModelAdminTests(TestCase): | |||||||
|         form = ma.get_formset(None).form |         form = ma.get_formset(None).form | ||||||
|         self.assertEqual(form._meta.fields, ['day', 'transport']) |         self.assertEqual(form._meta.fields, ['day', 'transport']) | ||||||
|  |  | ||||||
|  |     def test_lookup_allowed_allows_nonexistent_lookup(self): | ||||||
|  |         """ | ||||||
|  |         Ensure that a lookup_allowed allows a parameter | ||||||
|  |         whose field lookup doesn't exist. | ||||||
|  |         Refs #21129. | ||||||
|  |         """ | ||||||
|  |         class BandAdmin(ModelAdmin): | ||||||
|  |             fields = ['name'] | ||||||
|  |  | ||||||
|  |         ma = BandAdmin(Band, self.site) | ||||||
|  |         self.assertTrue(ma.lookup_allowed('name__nonexistent', 'test_value')) | ||||||
|  |  | ||||||
|     def test_field_arguments(self): |     def test_field_arguments(self): | ||||||
|         # If we specify the fields argument, fieldsets_add and fielsets_change should |         # If we specify the fields argument, fieldsets_add and fielsets_change should | ||||||
|         # just stick the fields into a formsets structure and return it. |         # just stick the fields into a formsets structure and return it. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user