Ticket #15032: explanation.txt

File explanation.txt, 1.6 KB (added by rene, 13 years ago)

Explanation of source of error

Line 
1The exception is raised because in file django/contrib/admin/options.py the method lookup_allowed in class BaseModelAdmin will return 'False' for this filter query.
2
3This method receives value 'employee__person_ptr__exact' in paramter 'lookup'.
4
5The 'lookup' is splitted by the lookup_seperator ('--'). Code snippet:
6
7209 parts = lookup.split(LOOKUP_SEP)
8
9So, 'parts' will now contain: ['employee', 'person_ptr', 'exact']
10
11
12The last term is ignored since it is a query term. Code snippet:
13
14211 # Last term in lookup is a query term (__exact, __startswith etc)
15212 # This term can be ignored.
16213 if len(parts) > 1 and parts[-1] in QUERY_TERMS:
17214 parts.pop()
18
19Now 'parts' contains: ['employee', 'person_ptr']
20
21The first element from 'parts' is tried to be a 'field' of the class. 'employee' indeed is, so the 'else' part of the exception handler is executed. A variable 'clean_lookup' is made which concats the two values of 'parts' together. 'clean_lookup' has the value 'employee__person_ptr'. This string is not included in 'list_filter' and not included in 'date_hierarchy'. So 'False' is returned. Lookup is not allowed. Code snippet:
22
23235 try:
24236 self.model._meta.get_field_by_name(parts[0])
25237 except FieldDoesNotExist:
26238 # Lookups on non-existants fields are ok, since they're ignored
27239 # later.
28240 return True
29241 else:
30242 if len(parts) == 1:
31243 return True
32244 clean_lookup = LOOKUP_SEP.join(parts)
33245 return clean_lookup in self.list_filter or clean_lookup == self.date_hierarchy
34
Back to Top