tastypie

Django Tastypie slow POST response

烂漫一生 提交于 2019-12-06 00:12:02
问题 I'm trying to implement a Tastypie Resource that allows GET & POST operations following a per user-permission policy, the model is pretty simple (similar to the Note model in Tastypie documentation) and the resource itself is also pretty simple, I just have an extra override_urls method to implement search with Haystack. My main problem now is that although running the project locally seems to be working fine, requests are fast and everything. Once I deployed the project (On Linode, using

How to get authorized user object in django-tastypie

回眸只為那壹抹淺笑 提交于 2019-12-05 19:27:46
I need to get authorized user object in hydrate method, something like that: class SalepointResource(ModelResource): def hydrate(self, bundle): user = bundle.request.user But request here is empty HttpRequest object, and doesn't have user method, although user is authorized. Is there any way to get user object? With TastyPie 0.9.15, I find this works: def hydrate_user(self, bundle): bundle.obj.user = bundle.request.user return bundle with no need for subclassing ModelResource . Here user is a ForeignKey of the model and the resource. I'm posting this as an answer because although it looks

How to hydrate a resource_uri in django-tastypie?

流过昼夜 提交于 2019-12-05 18:08:31
I just have a Resource uri, like '/api/v1/myobjectresource/23/' , and I need to hydrate it. It means, I want to instantiate MyObject(pk=23) from its resource_uri . How should I do this? Extracted from https://gist.github.com/794424 def get_resource_uri(self, bundle_or_obj): kwargs = { 'resource_name': self._meta.resource_name, } if isinstance(bundle_or_obj, Bundle): kwargs['pk'] = bundle_or_obj.obj.id # pk is referenced in ModelResource else: kwargs['pk'] = bundle_or_obj.id if self._meta.api_name is not None: kwargs['api_name'] = self._meta.api_name return self._build_reverse_url('api_dispatch

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

元气小坏坏 提交于 2019-12-05 17:48:07
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 @urlRoot+@id+'/?format=json' defaults: { name: 'Anon', address: new Address } ... and then I do this ..

Get model object from tastypie uri?

☆樱花仙子☆ 提交于 2019-12-05 08:36:45
How do you get the model object of a tastypie modelresource from it's uri? for example: if you were given the uri as a string in python, how do you get the model object of that string? Tastypie's Resource class (which is the guy ModelResource is subclassing ) provides a method get_via_uri(uri, request) . Be aware that his calls through to apply_authorization_limits(request, object_list) so if you don't receive the desired result make sure to edit your request in such a way that it passes your authorisation. A bad alternative would be using a regex to extract the id from your url and then use

Django tastypie: Resource show different in detailed request as in list request

我的未来我决定 提交于 2019-12-05 07:57:01
I Am just starting with django tastypie, and I Am enthousiastic about it. My question: I Am searching for the same feature as in the admin view: specify for foreignkey fields what to see in the list response of other objects and what in the detailed response. let's say this is my simplyfied model: class Location(models.Model): name = models.CharField(max_length=256, blank=True) longitude = models.FloatField(blank=True, default=0.0) latitude = models.FloatField(blank=True, default=0.0) description = models.CharField(max_length=256, blank=True) shortname = models.CharField(max_length=256, blank

Tastypie with application/x-www-form-urlencoded

烂漫一生 提交于 2019-12-05 07:10:58
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 indicated 'application/x-www-form-urlencoded' had no available deserialization method. Please check your

Filtering Error: Lookups are not allowed more than one level deep

♀尐吖头ヾ 提交于 2019-12-05 07:02:03
问题 From looking around at what others are doing this should be working, but I an error saying: Lookups are not allowed more than one level deep on the 'photos' field. Here is the code that I have. I've tried a few slight variations with how I set things up but I've had no luck. class CollectionResource(ModelResource): photos = fields.ToManyField('photoproject.apps.kit.api.PhotoResource', 'photo_set', null=True, full=True) class Meta: authorization = Authorization() resource_name = 'collection'

Django Tastypie

最后都变了- 提交于 2019-12-05 05:29:20
问题 I am creating a mobile app where I need to use authentication. How can I achieve the following: I need to create a user. After creating the user it needs to send Api_client and a secret as a response to the user. I have a function to perform verification. After creating the user it needs to call the function for mobile verification. Importantly, how can I stop a user who uses a for loop and starts adding users? I tried this: models.signals.post_save.connect(create_api_key, sender=User) That

Tastypie: I want to get items like “/places/{PLACE_ID}/comments” but how?

爱⌒轻易说出口 提交于 2019-12-05 02:04:49
问题 Let's say I want to get comments about a place. I want to make this request: /places/{PLACE_ID}/comments How can I do this with TastyPie? 回答1: Follow the example in Tastypie's docs and add something like this to your places resource: class PlacesResource(ModelResource): # ... def prepend_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/comments%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_comments'), name="api_get_comments"), ] def get_comments