tastypie

Django Tastypie Override URL with slug

空扰寡人 提交于 2019-12-13 02:56:07
问题 I have a similar coce: def override_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"), ] Which produces an URL like: /api/v1/nodes/<slug>/ Everything fine except that self.get_resource_uri(bundle) returns /api/v1/nodes/<id>/ and I cannot compare the current URL with the resource URI effectively. What am I doing wrong? Solution: working code I implemented the proposed solution

Django tastypie resources Import Error

天涯浪子 提交于 2019-12-13 02:25:49
问题 I am getting this error while running my django application. Internal Server Error: / Traceback (most recent call last): File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/handlers/base.py", line 101, in get_response resolver_match = resolver.resolve(request.path_info) File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/urlresolvers.py", line 318, in resolve for pattern in self.url_patterns: File "/Users

Why am I getting a NoneType HttpRequest with tastypie POST request

杀马特。学长 韩版系。学妹 提交于 2019-12-12 18:16:28
问题 It works fine on my localhost during development but when I deployed it on the server I get an empty request. class MyPinResource(Resource): pin = fields.CharField(attribute='pin', null=True) class Meta: resource_name = 'my-pin' authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() always_return_data = True include_resource_uri = False object_class = ApiObject allowed_methods = ['post'] def detail_uri_kwargs(self, bundle_or_obj): if isinstance(bundle_or_obj, Bundle):

Connection PhoneGap with localhost webservice

血红的双手。 提交于 2019-12-12 10:39:20
问题 I have a problem connecting with my webserwisem PhoneGap (Django + TastyPie). My PhoneGap - version - 3.3.0. Calling the POST or GET with plain html - everything is ok The problem starts when I move the project to the emulator - the transfer can not in any way connect. Besides clicking on the link gets "Error loading page". My xml (res/xml/config.xml): <?xml version="1.0" encoding="utf-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Django-tastypie pass request.user to custom save method

為{幸葍}努か 提交于 2019-12-12 10:26:16
问题 Since my model's custom save method takes request.user as an argument I'm unable to do POST/PUT requests. TypeError at /api/obsadmin/observation/23 save() takes at least 2 arguments (1 given) I'm using SessionAuthentication() and have included the CSRF token. Here's the relevant model part: def save(self, user, owner=None, *args, **kwargs): self.updated_by = user.id super(ObsModel, self).save(*args, **kwargs) And the resource: class ObservationResource2(ModelResource): comments = fields

Posting data to create related Tastypie resources simultaneously?

岁酱吖の 提交于 2019-12-12 09:19:06
问题 Given two related Django models A and B in a OneToMany relationship: models.py class A(models.Model): name = models.CharField(max_length=5) class B(models.Model): name = models.CharField(max_length=5) a = models.ForeignKey(A) And given (potentially non-optimal) Tastypie resources: api.py class AResource(ModelResource): bs = fields.ToManyField( 'projectname.api.BResource', 'bs', full = True) class Meta: queryset = A.objects.all() class BResource(ModelResource): a = fields.ToOneField( AResource

Django-tastypie One-To-Many relationship

喜你入骨 提交于 2019-12-12 08:00:03
问题 I'm trying to create a resource (Observation) that has 0 to unlimited comments. I'm stuck at the following error: "error": "The model '<Observation: Observation object>' has an empty attribute 'comments' and doesn't allow a null value." Also, adding null=True to comments = (...) will result in empty comment objects even though there should be comments for observations in question. I've also tried messing around with CommentResource2 path by changing it to full path. I've been following the

How to do automatic filtering based on the current user with tastypie

拜拜、爱过 提交于 2019-12-12 03:05:46
问题 I'm using tastypie with the DjangoAuthorization method. I have a StudentResource like this : class StudentResource(ModelResource): friends = fields.ToManyField(StudentResource, 'friends', null=True) class Meta: queryset = Student.objects.all() resource_name = 'student' authorization = DjangoAuthorization() So each of my student has many friends. Now, I'd like to return, when my user is making an API call only his friends. (based on his django id). (I don't want to just add a filter to my

Distance Spatial Queries with Tastypie

半世苍凉 提交于 2019-12-12 01:45:51
问题 Not sure how to use distance_lte spatial filters with tasty-pie. I can use the contains spatial filter i am unable to figure out the format for the distance_lte filter. Here is what I have tried: http://www.domain.com/myapp/api/v1/location/?format=json&coord__distance_lte={"type": "Point", "coordinates": [153.09537, -27.52618]},D(m=5) Which returns {"error": "Invalid resource lookup data provided (mismatched type)."} 回答1: From the tastypie sourcecode: # If we are filtering on a

Django Tastypie - serving emoji that are stored in db

我的梦境 提交于 2019-12-12 01:35:26
问题 I'm using django and tastypie for my api. the db is MySQL . After a few days of fiddling around i managed to store emoji icons in the db using utf8mb4 character set. When querying the db directly from the console (on a mac), i see the emoji fine, but when pulling them from the api (for example using the browser), the json shows question marks. This leads me to believe the issue is not with the db but with django/tastypie db connection. How do i go about it? 回答1: The solution is in DJango