tastypie

how to access POST data inside tastypie custom Authentication

允我心安 提交于 2019-11-29 17:47:14
问题 I'm trying to write custom Authentication in tastypie. Basically, I want to do the authentication using the post parameters and I don't want to use the django auth at all, so my code looks something like: class MyAuthentication(Authentication): def is_authenticated(self, request, **kwargs): if request.method == 'POST': token = request.POST['token'] key = request.POST['key'] return is_key_valid(token,key) This is more or less the idea. The problem is that I keep getting the following error:

Including child resources in a Django Tastypie API

江枫思渺然 提交于 2019-11-29 14:39:49
问题 I'm planning a site with Django and Tastypie for the REST API, and I'm having a tough time figuring out the "right" way to include child resources in a returned resource. As a sandbox, I made a small app with a Ticket model and a TicketComment model, where comments belong to a ticket. I looked at the Tastypie Cookbook recipe on nested resources (http://django-tastypie.readthedocs.org/en/latest/cookbook.html#nested-resources), but I'm having a hard time understanding why I should do that. The

appending multiple querystring variables with curl

你。 提交于 2019-11-29 11:24:26
问题 I keep getting a 401 response when I try to use authentication = ApiKeyAuthentication() in my ModelResource. I looked at Django Tastypie: How to Authenticate with API Key and he uses the get parameters to solve his issue. If I try use get parameters it picks up username but not api_key! This works in browser http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 Sending via curl in terminal doesn't pickup api_key parameter curl --dump-header -

Tastypie, add element to a many to many relationship

故事扮演 提交于 2019-11-29 10:05:29
I'm building a django tastypie api, and I have a problem with adding elements in ManyToMany relationships Example, models.py class Picture(models.db): """ A picture of people""" people = models.ManyToManyField(Person, related_name='pictures', help_text="The people in this picture", ) class Person(models.db): """ A model to represet a person """ name = models.CharField(max_length=200, help_text="The name of this person", ) resources: class PictureResource(ModelResource): """ API Resource for the Picture model """ people = fields.ToManyField(PersonResource, 'people', null=True, related_name=

Django Tastypie not Updating Resource with ManyToManyField

给你一囗甜甜゛ 提交于 2019-11-29 08:48:50
Why doesn't my resource with a ManyToManyField update with this PUT request? curl --dump-header - -H "Content-Type: application/json" -X PUT --data '{"uuid":"blah","pass_token":"blah","favorites": ["/api/v1/organizations/1/"]}' http://localhost:8000/api/v1/devices/2/ I get this response: HTTP/1.0 400 BAD REQUEST Date: Wed, 11 Jul 2012 22:21:15 GMT Server: WSGIServer/0.1 Python/2.7.2 Content-Type: application/json; charset=utf-8 {"favorites": ["\"/api/v1/organizations/1/\" is not a valid value for a primary key."]} Here are my resources: class OrganizationResource(ModelResource): parent_org =

Tastypie obj_create - how to use newly created object?

江枫思渺然 提交于 2019-11-29 07:21:45
When a new item is created using Tastypie, I want to be able to add it to a user's attribute which is a many-to-many field. RIght now my obj_create looks like this: def obj_create(self, bundle, request=None, **kwargs): return super(GoalResource, self).obj_create(bundle, request, user=request.user) I want to create the new object, but when I want to be able to add it to the request.user's attribute goal_list. But, what I have will immediately create the object in the database. How would I create the object and then add it to the user's goal_list attribute? You didn't show us your resource

underscore.js - _.groupBy nested attribute

萝らか妹 提交于 2019-11-29 06:57:04
Tastypie returns an array, including nested resources as follows: data = [ {"adult_price": "123", "child_price": "123", "currency": [{"abbrev": "USD", "id": "1", "name": "US Dollars", "resource_uri": "/api/v1/currency/1/", "symbol": "$"}], "day": [{"day_of_week": "TUE", "id": "2", "resource_uri": "/api/v1/days/2/"}], "description": "Please enter the tour description here", "id": "1", "important": "ex. Please contact us to negotiate a price if you want to book the Fiat for 1 person only.", "location": [{"id": "1", "name": "Dublin", "resource_uri": "/api/v1/location/1/"}], "name": "test dublin",

Partial Updates (aka PATCH) using a $resource based service?

耗尽温柔 提交于 2019-11-29 03:00:18
问题 We're building a web application using Django/TastyPie as the back-end REST service provider, and building an AngularJS based front end, using lots of $resource based services to CRUD objects on the server. Everything is working great so far! But, we would like to reduce the amount of data that we're shipping around when we want to update only one or two changed fields on an object. TastyPie supports this using the HTTP PATCH method. We have defined a .diff() method on our objects, so we can

Returning data on POST in django-tastypie

≯℡__Kan透↙ 提交于 2019-11-29 01:47:01
问题 I consider it a standard that an object-creating function returns the newly created object. So, any idea how do you do that in tastypie? When I send the POST request, the object is created, I get nothing in response, though. What I would like is to receive the JSON form of the newly created object (or at least the PK). I tried overriding the dehydrate method, but it seems that it's not even called when it comes to POST. Any ideas? 回答1: Can't believe the answer was so easy. http://django

Tastypie filtering with multiple values

点点圈 提交于 2019-11-29 01:08:07
问题 I had a simple question on filtering in tastypie. I want to filter with multiple values. For example: /api/v1/message/?accountId=1,5,12 This doesnt work. Any idea how i can do this? Do i need to use advanced filtering? If yes, how do I go about creating such a filter? A simple effortless example of puesdo-code would be great! Thanks! 回答1: Hmm, You can do this: /api/v1/message/?accountId__in=1&accountId__in=5&accountId__in=12 PS: in filtering meta attribute, add {'accountId': ALL} 回答2: The