Ticket #12173: filterspec_or_support.patch
File filterspec_or_support.patch, 2.1 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/views/main.py
27 27 TO_FIELD_VAR = 't' 28 28 IS_POPUP_VAR = 'pop' 29 29 ERROR_FLAG = 'e' 30 FILTERSPEC_OR_PREFIX = '__or__' 30 31 31 32 # Text to display within change-list table cells if the value is blank. 32 33 EMPTY_CHANGELIST_VALUE = '(None)' … … 87 88 p = self.params.copy() 88 89 for r in remove: 89 90 for k in p.keys(): 90 if k.startswith(r) :91 if k.startswith(r) or k.startswith(FILTERSPEC_OR_PREFIX): 91 92 del p[k] 92 93 for k, v in new_params.items(): 93 94 if v is None: … … 187 188 188 189 # Apply lookup parameters from the query string. 189 190 try: 190 qs = qs.filter(**lookup_params) 191 or_params = {} 192 and_params = lookup_params 193 for key, value in lookup_params.items(): 194 if key.startswith(FILTERSPEC_OR_PREFIX): 195 or_params[key[len(FILTERSPEC_OR_PREFIX):]] = and_params.pop(key) 196 197 if or_params: 198 and_queries = [models.Q(**{key: value}) for key, value in and_params.items()] 199 or_queries = [models.Q(**{key: value}) for key, value in or_params.items()] 200 if and_queries: 201 qs = qs.filter(reduce(operator.and_, and_queries) | reduce(operator.or_, or_queries)) 202 else: 203 qs = qs.filter(**lookup_params) 204 191 205 # Naked except! Because we don't have any other way of validating "params". 192 206 # They might be invalid if the keyword arguments are incorrect, or if the 193 207 # values are not in the correct type, so we might get FieldError, ValueError, 194 # Vali cationError, or ? from a custom field that raises yet something else208 # ValidationError, or ? from a custom field that raises yet something else 195 209 # when handed impossible data. 196 210 except: 197 211 raise IncorrectLookupParameters