Skip to content

Instantly share code, notes, and snippets.

View namsral's full-sized avatar

Lars Wiegman namsral

View GitHub Profile
@namsral
namsral / gist:1717329
Created February 1, 2012 14:33
Mixin for the Djando Rest Framework (DFR) to auto-complete objects on creating.
class AutoCompleteResourceMixin(ResourceMixin):
def validate_request(self, data, files=None):
"""
Auto-complete objects when they are created.
A REST equivalent to auto-populate for Django web forms.
"""
method = self.view._method if hasattr(self.view, '_method') else None
@namsral
namsral / gist:1716333
Created February 1, 2012 10:10
Mixin for the Djando Rest Framework (DFR) to filter objects by authenticated user.
class AuthenticatedUserResourceMixin(ResourceMixin):
permissions = (IsAuthenticated,)
def build_query(self, *args, **kwargs):
tmp = dict(kwargs)
if BaseRenderer._FORMAT_QUERY_PARAM in tmp:
del tmp[BaseRenderer._FORMAT_QUERY_PARAM]