Ticket #14999: 14999-trunk.diff
File 14999-trunk.diff, 3.3 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
a b 213 213 if len(parts) > 1 and parts[-1] in QUERY_TERMS: 214 214 parts.pop() 215 215 216 # Special case -- foo__id__exact and foo__id queries are implied 217 # if foo has been specificially included in the lookup list; so 218 # drop __id if it is the last part. However, first we need to find 219 # the pk attribute name. 220 model = self.model 221 pk_attr_name = None 222 for part in parts[:-1]: 223 field, _, _, _ = model._meta.get_field_by_name(part) 224 if hasattr(field, 'rel'): 225 model = field.rel.to 226 pk_attr_name = model._meta.pk.name 227 elif isinstance(field, RelatedObject): 228 model = field.model 229 pk_attr_name = model._meta.pk.name 230 else: 231 pk_attr_name = None 232 if pk_attr_name and len(parts) > 1 and parts[-1] == pk_attr_name: 233 parts.pop() 216 if len(parts) > 1: 217 # Special case -- foo__id__exact and foo__id queries are implied 218 # if foo has been specificially included in the lookup list; so 219 # drop __id if it is the last part. However, first we need to find 220 # the pk attribute name. 221 model = self.model 222 pk_attr_name = None 223 for part in parts[:-1]: 224 field, _, _, _ = model._meta.get_field_by_name(part) 225 if hasattr(field, 'rel'): 226 model = field.rel.to 227 pk_attr_name = model._meta.pk.name 228 elif isinstance(field, RelatedObject): 229 model = field.model 230 pk_attr_name = model._meta.pk.name 231 else: 232 pk_attr_name = None 233 if pk_attr_name and parts[-1] == pk_attr_name: 234 parts.pop() 234 235 235 236 try: 236 237 self.model._meta.get_field_by_name(parts[0]) … … 239 240 # later. 240 241 return True 241 242 else: 243 if len(parts) == 1: 244 return True 242 245 clean_lookup = LOOKUP_SEP.join(parts) 243 246 return clean_lookup in self.list_filter or clean_lookup == self.date_hierarchy 244 247 -
tests/regressiontests/admin_views/tests.py
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
a b 355 355 ) 356 356 357 357 try: 358 self.client.get("/test_admin/admin/admin_views/ stuff/?color__value__startswith=red")358 self.client.get("/test_admin/admin/admin_views/thing/?color__value__startswith=red") 359 359 except SuspiciousOperation: 360 360 self.fail("Filters are allowed if explicitly included in list_filter") 361 361 362 try: 363 self.client.get("/test_admin/admin/admin_views/person/?alive__exact=1") 364 except SuspiciousOperation: 365 self.fail("Filters should be allowed if they involve a local field without the need to whitelist them in list_filter or date_hierarchy.") 366 362 367 class SaveAsTests(TestCase): 363 368 fixtures = ['admin-views-users.xml','admin-views-person.xml'] 364 369