| 87 | def search_filter(self, lookups, data, **kwargs): |
| 88 | """Runs filter using field lookups and values from supplied dicts. |
| 89 | For example, running search_filter with -- |
| 90 | lookups = {'myfield': 'myfield', 'mytext': 'mytext__startswith', 'mydate': 'mydata__lte'} |
| 91 | data = {'myfield': 'somevalue', 'mytext': 'h', 'mydate': ''} |
| 92 | Would be the same as -- |
| 93 | filter(myfield='somevalue', mytext__startswith='h') |
| 94 | Skips empty values. Useful for searching against form or request data. |
| 95 | """ |
| 96 | sf_args = {} |
| 97 | for item in lookups: |
| 98 | if data.has_key(item): |
| 99 | if data[item] != '' and data[item] != None: |
| 100 | sf_args[lookups[item]] = data[item] |
| 101 | sf_args.update(kwargs) |
| 102 | return self.get_query_set().filter(**sf_args) |
| 103 | |