tastypie

How to change tastypie time format

一个人想着一个人 提交于 2019-12-10 09:46:40
问题 I'm writing an API server using Django 1.4.2 and Tastypie 0.9.11. For all the datetime output, I'm using the default iso 8601 format, for example: "2012-11-20T02:48:19+00:00". But I want to get a "2012-11-20T02:48:19Z" format. How to do it easily without customizing each datetime field? 回答1: Formatting a date is probably best done in the templates. However, Tastypie allows you to add or modify fields returned by the API using the dehydrate cycle. For example: # models.py class MyModel(models

How do I load sub-models with a foreign key relationship in Backbone.js?

≡放荡痞女 提交于 2019-12-10 09:42:59
问题 Sorry if this is a bit convoluted... I am still learning Backbone.js... What is the proper way to load & save Backbone models that have sub-models within themselves? (And should I even be having sub-models?) For example, (pardon the coffeescript), if I have something like: class Address extends Backbone.Model urlRoot: '/api/v1/address/' url: -> return @urlRoot+@id+'/?format=json' defaults: {'city': '', 'state': ''} class Person extends Backbone.Model urlRoot: '/api/v1/person/' url: -> return

Tastypie with application/x-www-form-urlencoded

时光怂恿深爱的人放手 提交于 2019-12-10 04:32:53
问题 I'm having a bit of difficulty figuring out what my next steps should be. I am using tastypie to create an API for my web application. From another application, specifically ifbyphone.com, I am receiving a POST with no headers that looks something like this: post data:http://myapp.com/api/ callerid=1&someid=2&number=3&result=Answered&phoneid=4 Now, I see in my server logs that this is hitting my server.But tastypie is complaining about the format of the POST. {"error_message": "The format

Django and REST API to serve calculation-based requests

放肆的年华 提交于 2019-12-10 02:58:48
问题 I wrote a machine learning application in Django so a user can specify in a form some parameters and train a model. Once the model is trained, I want to serve requests like: curl http://localhost:8000/.../?model_input='XYZ' and I want Django returns the output of the model given the input XYZ. Every example I saw from Tastypie or REST framework builds its response from a queryset. How can I proceed if the response is not the result of a queryset but the result of in-memory pure calculation?

Populating a tastypie resource for a multi-table inheritance Django model

巧了我就是萌 提交于 2019-12-09 17:58:53
问题 Given the following code I was wondering how to populate RecordsResource with each real record data: models.py class Record(models.Model): content_type = models.ForeignKey(ContentType, editable=False, null=True) user = models.ForeignKey(User, related_name='records') issued = models.DateTimeField(auto_now_add=True) date = models.DateField() def save(self, *args, **kwargs): if not self.content_type: self.content_type = ContentType.objects.get_for_model(self.__class__) super(Record, self).save(

Does SessionAuthentication work in Tastypie for HTTP POST?

≡放荡痞女 提交于 2019-12-09 17:54:00
问题 I am able to do GET to work with SessionAuthentication and Tastypie without setting any headers except for content-type to application/json . HTTP POST however just fails even though the Cookie in the Header has the session id. It fails with a 401 AuthorizationHeader but it has nothing to do with Authorization. Changing SessionAuthentication to BasicAuthentication and passing username/password works too. Has anyone ever got SessionAuthentication to work with POST with Tastypie? 回答1: Yes I

Download anchor link with authorization header

爱⌒轻易说出口 提交于 2019-12-09 14:14:28
问题 I have a link that I would like to add to my javascript (Marionette/Backbone) single page application that will download an Excel file to the user's local drive via the browser's file save. A typical HTTP request would be: GET /api/v1/objects/?format=xls HTTP/1.1 Authorization: ApiKey username:apikey Host: api.example.com Connection: close User-Agent: Paw 2.0.5 (Macintosh; Mac OS X 10.9.2; en_US) Content-Length: 0 Which results in the following typical response: HTTP/1.1 200 OK Server:

Django Tastypie: Imlementing Many To Many “through” relationships

安稳与你 提交于 2019-12-09 13:15:34
问题 I have searched about this issue a lot and gone through a bunch of related questions on Stack Overflow, but there doesn't seem to be a definitive answer about how to implement many-to-many relationships "through" an intermediate model (or maybe I missed it). I have a model named Sample which has a many-to-many relationship with Region. There is an intermediate model which connects the two, named SampleRegion. I am currently not saving any extra information on the intermediate model, but I

Using tastypie resource in view

强颜欢笑 提交于 2019-12-09 12:42:39
问题 my first question here : So I'm using tastypie to have api's for my app. I want to be able to use tastypie to render json and then include that in a django view so that I can bootstrap my app's data. There is an example of this in django tastypie cookbook here : http://django-tastypie.readthedocs.org/en/latest/cookbook.html#using-your-resource-in-regular-views The problem is that I CANNOT get this to work, I've tried variants from simpler to more complex and I just cant get it, here some code

Tastypie Nested Resources - cached_obj_get() takes exactly 2 arguments (1 given)

半城伤御伤魂 提交于 2019-12-08 19:18:05
问题 I'm trying to use the example here: http://django-tastypie.readthedocs.org/en/latest/cookbook.html#nested-resources for some reason i get: cached_obj_get() takes exactly 2 arguments (1 given) even though i clearly call it with 2 arguments (exactly like in the aforementioned example. this is my code: def prepend_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/feed%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_feed'), name="api_get_feed"), ] def get