tastypie

django tastypie update two models

核能气质少年 提交于 2019-12-21 05:51:32
问题 I have a problem with tastypie regarding updates to two models with one (POST) api call. We have two models, an user model and a candidate model which references the user model. We want to publish the candidate model via the api interface, but want to hide the user model. So, as a first step I merge the user model fields with the candidate model fields in the dehydrate process. This is working completly fine. The problem is, that I can't figure out, how to do it the other way round (hydrate

Uploading files to tastypie with Backbone?

我的梦境 提交于 2019-12-21 02:58:06
问题 Checked some other questions and I think my tastypie resource should look something like this: class MultipartResource(object): def deserialize(self, request, data, format=None): if not format: format = request.META.get('CONTENT_TYPE', 'application/json') if format == 'application/x-www-form-urlencoded': return request.POST if format.startswith('multipart'): data = request.POST.copy() data.update(request.FILES) return data return super(MultipartResource, self).deserialize(request, data,

How to load the foreign keys elements in Tastypie

喜夏-厌秋 提交于 2019-12-20 20:15:12
问题 In my Django model, I have 10 fields and there are 3 fields which are foreign keys. In my JSON data which is received from a GET request, I am getting all the fields but not the foreign keys. I have also done this, but I am still not getting those fields in the JSON data: DataFields = MyData._meta.get_all_field_names() class MyResource(ModelResource): class Meta: queryset = MyData.objects.all() resource_name = 'Myres' serializer = Serializer(formats=['json']) filtering = dict(zip(DataFields,

Connect facebook phonegap login with django allauth

我的未来我决定 提交于 2019-12-20 09:45:29
问题 I'm building up an app that should allow the user to sign up / sign in with Facebook and then he should be able to login (always via Facebook ) to the "main" website To be honest it's a bit more complicated than this. That's because I'm using django-tastypie and django-allauth in the main website to allow sign up, login, and browsing of our API Basically I want to make the mobile app user browse the tastypie API (accessible only if logged and if you're an user in the main website) and grant

How to make sure that my AJAX requests are originating from the same server in Python

蹲街弑〆低调 提交于 2019-12-20 09:13:22
问题 I have already asked a question about IP Authentication here: TastyPie Authentication from the same server However, I need something more! An IP address could be very easily spoofed. Scenario: My API (TastyPie) and Client App (in javascript) are on the same server/site/domain. My users don't login. I want to consume my API in my javascript client side. Question: How can I make sure (authentication) that my AJAX requests are originating from the same server ? I'm using Tatypie. I need to

Tastypie- Append parameters to URI

这一生的挚爱 提交于 2019-12-20 05:41:13
问题 How do I append parameters to a URL in Django Tastypie. Here is url.py. from modules.actions.views import InstallationResource,ApiActionsResource from tastypie.api import Api from modules.actions import views v1_api = Api(api_name='v1') v1_api.register(ApiActionsResource()) urlpatterns = patterns('', url(r'^(?P<action_type>.+)', views.ApiActionsResource.as_view), ) I need to pass action_type=1 to the URL. How do I do it? 回答1: You need to include your api urls like this: urlpatterns = patterns

How to filter ToManyField of django-tastypie by request.user?

*爱你&永不变心* 提交于 2019-12-19 03:46:11
问题 I'm building an API with tastypie for a django app for data based on the user. The resources are like this: class PizzaResource(ModelResource): toppings = fields.ToManyField( 'project.app.api.ToppingResource', 'topping_set' ) class Meta: authentication = SessionAuthentication() queryset = Pizza.objects.all() def apply_authorization_limits(self, request, object_list): return object_list.filter(users=request.user) class ToppingResource(ModelResource): pizza = fields.ForeignKey(PizzaResource,

Django & TastyPie: request.POST is empty

杀马特。学长 韩版系。学妹 提交于 2019-12-18 19:09:33
问题 I'm trying to do a POST using curl: curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"item_id": "1"}' http://www.mylocal.com:8000/api/1/bookmarks/ However, request.POST is always empty. Below is my ModelResource code: class BookmarkResource(ModelResource): class Meta: queryset = Bookmark.objects.all() resource_name = 'bookmarks' fields = ['id', 'tags'] allowed_methods = ['get', 'post', 'delete', 'put'] always_return_data = True authorization= Authorization() include

Django Tastypie - Filtering ToManyField resource with URL parameter

不问归期 提交于 2019-12-18 18:38:55
问题 I am working on implementing an API for my Django (v1.5) application using Tastypie. I would like to be able to filter/limit the related resources I get when the parent resource. Here are my (simplified) models: # myapp/models.py class User(models.Model): number = models.IntegerField() device_id = models.CharField(verbose_name="Device ID", max_length=255) timezone = models.CharField(max_length=255, blank=True) def data(self, limit=0): result = Data.objects.filter(patient_id = self.id).order

Tastypie APIKey authentication

断了今生、忘了曾经 提交于 2019-12-18 10:55:29
问题 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