This file contains 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
def save_m2m(self, bundle): | |
""" | |
Handles the saving of related M2M data. | |
Due to the way Django works, the M2M data must be handled after the | |
main instance, which is why this isn't a part of the main ``save`` bits. | |
Currently slightly inefficient in that it will clear out the whole | |
relation and recreate the related data as needed. | |
""" |
This file contains 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
''' | |
I've received several requests for examples of my pull request for tastypie. | |
https://github.com/toastdriven/django-tastypie/pull/214 | |
''' | |
# in your models.py for instance: | |
class TimeLogManager( models.Manager ): | |
use_for_related_fields = True | |
def for_user(self, user): |
This file contains 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
class YourResource(ModelResource): | |
def wrap_view(self, view): | |
""" | |
Wraps views to return custom error codes instead of generic 500's | |
""" | |
@csrf_exempt | |
def wrapper(request, *args, **kwargs): | |
try: |
This file contains 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
class SimpleOwnerAuthorization(Authorization): | |
''' | |
Does what it says: filters objects by their owner (user). | |
''' | |
def __init__(self, ownerfilter=None, *args, **kwargs): | |
self.ownerfilter = ownerfilter # the user field i.e. 'person__user' | |
def is_authorized(self, request, object=None): | |
return True # for now |