Created
September 9, 2013 21:41
-
-
Save jrm2k6/6501913 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url called http://localhost:8000/api/user/?password__exact=103a8ab6cc265e99a4ce8cea60e63d1f8fc0004f&email__exact=jeremy.dagorn@gmail.com | |
| class ReaderUserResource(ModelResource): | |
| class Meta: | |
| queryset = ReaderUser.objects.all() | |
| resource_name = 'user' | |
| filtering = { | |
| 'email': ['exact'], | |
| 'password': ['exact'], | |
| 'query': ['exact',], | |
| } | |
| def build_filters(self, filters=None): | |
| print filters | |
| if filters is None: | |
| filters = {} | |
| orm_filters = super(ReaderUserResource, self).build_filters(filters) | |
| if('query' in filters): | |
| query = filters['query'] | |
| print query | |
| qset = ( | |
| Q(email__exact=query) | | |
| Q(password__exact=query) | |
| ) | |
| orm_filters.update({'custom': qset}) | |
| return orm_filters | |
| def apply_filters(self, request, applicable_filters): | |
| if 'custom' in applicable_filters: | |
| custom = applicable_filters.pop('custom') | |
| else: | |
| custom = None | |
| semi_filtered = super(ReaderUserResource, self).apply_filters(request, applicable_filters) | |
| return semi_filtered.filter(custom) if custom else semi_filtered |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment