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
from django.conf.urls.defaults import * | |
from tastypie.api import Api | |
from myapp.api import EntryResource, UserResource | |
v1_api = Api(api_name = 'v1') | |
v1_api.register(CardResource()) | |
v1_api.register(TrackResource()) | |
mobile_api = Api(api_name='mobile') | |
mobile_api.register(CardResource()) |
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
$ curl -X POST -H 'Content-Type: application/json' -u nate:nate | |
--data '{"recipient_name" : "Anna", | |
"track_set" : "", | |
"interests" : "hamburgers, skating"}' | |
http://localhost:8000/api/card/ |
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
$ curl -X POST -H 'Content-Type: application/json' -u nate:nate | |
--data '{"recipient_name" : "Anna", | |
"track_set" : "", | |
"interests" : "hamburgers, skating"}' | |
http://localhost:8000/api/card/ |
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
$ curl -X POST -H 'Content-Type: application/json' -u nate:nate | |
--data '{"recipient_name" : "Anna", | |
"interests" : "dancing, coffee"}' | |
http://localhost:8000/api/card/ |
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
{ | |
"create_date": "2011-06-06T06:41:31.454924", | |
"id": "1", | |
"interests": "dancing, coffee", | |
"intro_note": "", | |
"recipient_email": "", | |
"recipient_name": "Anna", | |
"recipient_phone": "", | |
"resource_uri": "/api/card/1/" | |
} |
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
{ | |
"create_date": "2011-06-06T06:41:31.454924", | |
"id": "1", | |
"interests": "dancing, coffee", | |
"intro_note": "", | |
"recipient_email": "", | |
"recipient_name": "Anna", | |
"recipient_phone": "", | |
"resource_uri": "/api/card/1/", | |
"track_set": |
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 post_list(self, request, **kwargs): | |
""" | |
Creates a new resource/object with the provided data. | |
Calls get_tracks to get all track info from various apis. | |
""" | |
deserialized = self.deserialize(request, request.raw_post_data, format=request.META.get('CONTENT_TYPE', 'application/json')) | |
bundle = self.build_bundle(data=dict_strip_unicode_keys(deserialized)) | |
self.is_valid(bundle, request) | |
updated_bundle = self.obj_create(bundle, request=request, user=request.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 CardResource(ModelResource): | |
track_set = fields.ToManyField(TrackResource, 'track_set', full=True) |
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 CardResource(ModelResource): | |
track_set = fields.ToManyField(TrackResource, 'track_set', full=True) | |
def get_object_list(self, request, *args, **kwargs): | |
return Card.objects.filter(user=request.user) | |
class Meta: | |
queryset = Card.objects.all() | |
resource_name = 'card' | |
authentication = BasicAuthentication() |
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 CardResource(ModelResource): | |
track_set = fields.ToManyField(TrackResource, 'track_set', full=True) | |
def get_object_list(self, request, *args, **kwargs): | |
return Card.objects.filter(user=request.user) |
OlderNewer