tastypie

appending multiple querystring variables with curl

a 夏天 提交于 2019-11-30 08:02:43
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 - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 Why

django-tastypie: Posting to a Resource having ManytoMany field with through relationship

落爺英雄遲暮 提交于 2019-11-30 05:45:45
问题 I'm working on a API for a project and I have a relationship Order/Products through OrderProducts like this: In models.py class Product(models.Model): ... class Order(models.Model): products = models.ManyToManyField(Product, verbose_name='Products', through='OrderProducts') ... class OrderProducts(models.Model): order = models.ForeignKey(Order) product = models.ForeignKey(Product) ... Now, when I load an Order through the API I'd like to get the related Products as well, so I tried this (with

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

匆匆过客 提交于 2019-11-30 05:09:25
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 determine which fields we want to send when we do an update. I just can't find any documentation on how

django-tastypie and many to many “through” relationships

我是研究僧i 提交于 2019-11-30 04:49:43
问题 In Django and Tastypie I'm attempting to figure out how to properly deal with Many to Many "through" relationships, like those found here: https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships Here are my sample models: class Ingredient(models.Model): name = models.CharField(max_length=100) description = models.TextField() class RecipeIngredients(models.Model): recipe = models.ForeignKey('Recipe') ingredient = models.ForeignKey('Ingredient') weight

Returning data on POST in django-tastypie

放肆的年华 提交于 2019-11-30 04:32:45
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? Can't believe the answer was so easy. http://django-tastypie.readthedocs.org/en/latest/resources.html#always-return-data Just add always_return_data = True to your

Tastypie - Nested Resource field not found

空扰寡人 提交于 2019-11-30 04:18:02
问题 I have this code: #api model class VideoResource(ModelResource): class Meta: queryset = Video.objects.all() include_resource_uri = False resource_name = 'video' authorization = DjangoAuthorization() class QuestionResource(ModelResource): user = fields.ToOneField(UserResource,'user',full=True) video = fields.ForeignKey(VideoResource,'video',full=True) class Meta: queryset = Question.objects.all() resource_name = 'question' include_resource_uri = False authorization = DjangoAuthorization() def

Convert a queryset to json using tastypie resource

烈酒焚心 提交于 2019-11-30 03:34:41
问题 I have a tastypie resource for a model. I also have a view which comes up with a queryset which needs to be serialised and sent to client. I am looking for a way to let tastypie resource handle the serialisation and dehydration of the queryset. I see that I can pass a single object to [Resource.build_bundle(self, obj=None, data=None, request=None)][1] to create a bundle and then pass the bundle to [Resource.full_dehydrate(self, bundle)][2] and finally call [Resource.serialize(self, request,

Tastypie filtering with multiple values

一笑奈何 提交于 2019-11-30 03:31:56
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! 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} The most recent version seems to work pretty easily - just use an "__in": /api/v1/message/?accountId__in=1,5,12 (I

Using non-AMD compatible javascript module with require.js?

可紊 提交于 2019-11-30 01:21:39
I'm using require.js to help organize my Backbone.js based application. I'm trying to figure out the right way to use a 3rd party javascript library that is not AMD compatible with require.js The library in questions is backbone-tastypie.js . Basically what the library does is monkeypatch some of the prototype methods of Backbone to provide simpler support for the TastyPie Django REST framework. It does this by directly manipulating the Backbone object in the global namespace. However, since I'm using Backbone.js as a require.js module, it isn't available when this library tries to access it.

Tastypie APIKey authentication

ぃ、小莉子 提交于 2019-11-30 00:38:16
How does the Tastypie APIKey authentication work? I know there is a signal as mentioned in the documentation: from django.contrib.auth.models import User from django.db import models from tastypie.models import create_api_key models.signals.post_save.connect(create_api_key, sender=User) However, when is this called? If I want to give a user their APIkey I know I can find it in the APIKey db that this create_api_key function adds the key into, but where and when do I call this models.signals.post_save function? Is this just another django model? I think it is? Is this called everytime a user