diff -rupN django/contrib/admin/filterspecs.py ../django/contrib/admin/filterspecs.py
|
|
../
|
class FilterSpec(object):
|
| 26 | 26 | def title(self): |
| 27 | 27 | raise NotImplementedError() |
| 28 | 28 | |
| 29 | | def get_query_set(self, cl, qs): |
| | 29 | def get_query_set(self, cl): |
| 30 | 30 | return False |
| 31 | 31 | |
| 32 | 32 | def consumed_params(self): |
diff -rupN django/contrib/admin/views/main.py ../django/contrib/admin/views/main.py
|
|
../
|
class ChangeList(object):
|
| 172 | 172 | order_type = params[ORDER_TYPE_VAR] |
| 173 | 173 | return order_field, order_type |
| 174 | 174 | |
| | 175 | def apply_filter_specs(self,qs,filter_dict): |
| | 176 | # Here we apply the results of Q objects collected from our FilterSpecs |
| | 177 | # The & operator becomes a sensible default which can be overridden in |
| | 178 | # particular cases. |
| | 179 | return qs.filter(reduce(operator.__and__(filter_dict.values()))) |
| | 180 | |
| 175 | 181 | def get_query_set(self): |
| 176 | 182 | qs = self.root_query_set |
| 177 | 183 | lookup_params = self.params.copy() # a dictionary of the query string |
| … |
… |
class ChangeList(object):
|
| 191 | 197 | lookup_params[key] = value.split(',') |
| 192 | 198 | |
| 193 | 199 | # Let every filter spec modify the qs and params to its liking |
| | 200 | # Redux to above comment -- Let every filter spec return a Q object |
| | 201 | |
| | 202 | filter_dict = {} # A handy repository for our collected Q objects |
| 194 | 203 | for filter_spec in self.filter_specs: |
| 195 | | new_qs = filter_spec.get_query_set(self, qs) |
| 196 | | if new_qs is not None and new_qs is not False: |
| 197 | | qs = new_qs |
| 198 | | # Only consume params if we got a new queryset |
| | 204 | new_q = filter_spec.get_query_set(self) |
| | 205 | if new_q: |
| | 206 | filter_dict[filter_spec] = new_q |
| | 207 | # Only consume params if we got a new Q obj |
| 199 | 208 | for param in filter_spec.consumed_params(): |
| 200 | 209 | try: |
| 201 | 210 | del lookup_params[param] |
| … |
… |
class ChangeList(object):
|
| 209 | 218 | else: |
| 210 | 219 | lookup_params[key] = True |
| 211 | 220 | |
| | 221 | # The below allows the user to override the querying assumption |
| | 222 | # among filters (x = y AND z = a AND ...) |
| | 223 | if filter_dict: |
| | 224 | qs = self.apply_filter_specs(filter_dict) |
| | 225 | |
| 212 | 226 | # Apply lookup parameters from the query string. |
| 213 | 227 | try: |
| 214 | 228 | qs = qs.filter(**lookup_params) |