tastypie

Django TastyPie Geo Distance Lookups

牧云@^-^@ 提交于 2019-12-23 17:28:04
问题 I'm using TastyPie for Geo-distance lookups. That is a bit difficult, because oficially its not supported by TastyPie. On Github (https://gist.github.com/1067176) I found the following code-sample: def apply_sorting(self, objects, options=None): if options and "longitude" in options and "latitude" in options: return objects.distance(Point(float(options['latitude']), float(options['longitude']))).order_by('distance') return super(UserLocationResource, self).apply_sorting(objects, options) It

How to have proper urls for nested resources in tastypie

寵の児 提交于 2019-12-23 04:47:34
问题 I'm using the Nested Resource cookbook pattern from tastypie, which can be found here, only I'm using many-to-many relationships. Which means the prepend urls, looks something like this: class ParentResource(ModelResource): children = fields.ToManyField(ChildResource, 'children') def prepend_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/childrens%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_children'), name="api_get_children"), ] def get

Django, TastyPie, Authentication, and custom middleware headache

a 夏天 提交于 2019-12-23 02:46:11
问题 I have a Django web application which requires authentication across the whole site. I've accomplished that with custom middleware which basically test if request.user.is_anonymous and, if they are, redirects them to the login page. It looks like this: from django.contrib.auth.views import login from django.contrib.auth import authenticate from django.http import HttpResponseRedirect, HttpResponse from django.utils import simplejson from django.core import serializers class SiteLogin: "This

How do I set the authorization header for tastypie?

蹲街弑〆低调 提交于 2019-12-22 21:46:15
问题 When passing values as parameters in the request it works: curl "http://localhost:8080/wordgame/api/v1/rounds/?username=test_user&api_key=12345678907a9cb56b7290223165e0a7c23623df&format=json" However, it does not work when I try to pass the values in as headers. This results in a 401: curl -H "Authorization: ApiKey test_user:12345678907a9cb56b7290223165e0a7c23623df" -H "Accept: application/json" http://localhost:8080/wordgame/api/v1/rounds/ I am using Tastypie ApiKeyAuthentication 回答1: Your

Significant overhead on Django apache vs. built-in dev server

守給你的承諾、 提交于 2019-12-22 18:13:04
问题 I'm running Django/Tastypie on a soon-to-be production environment, however I am noticing significant overhead using Apache vs. using the built-in dev server. Apache is MUCH slower. Here are non-scientific bandwidth tests using ab: Apache: $ ab -n 100 -c 50 https://www.mydomain.com/api/v1/clock/?format=json This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www

django-tastypie: linking a ModelResource to a Resource

浪尽此生 提交于 2019-12-22 15:04:10
问题 I'm currently trying django-tastypie to design a RESTful api. I'm facing a problem: # the RevisionObject retrieve commits info through pysvn # This Resource is fully functionnal (RevisionObject code is not here) class RevisionResource(Resource): id = fields.CharField(attribute='revision') description = fields.CharField(attribute='message') author = fields.CharField(attribute='author') changed_path = fields.ListField(attribute='changed_paths') class Meta: object_class = RevisionObject allowed

How to combine mutiple resources in django-tastypie?

让人想犯罪 __ 提交于 2019-12-22 10:55:04
问题 Lets say I have three models Submission, Contact and SubmissionContact. class Submission(models.Model): title = models.CharField(max_length=255, verbose_name='Title') ... class Contact(models.Model): name = models.CharField(max_length=200, verbose_name='Contact Name') email = models.CharField(max_length=80, verbose_name='Contact Email') ... class SubmissionContact(models.Model): submission = models.ForeignKey(Submission) contact = models.Foreign(Contact, verbose_name='Contact(s)') Can I read

django-tastypie - How to make manytomany through relationship

我与影子孤独终老i 提交于 2019-12-22 04:43:29
问题 I'm working on a API for a project and I have a relationship Order/Products through OrderProducts like this: In catalog/models.py class Product(models.Model): ... In order/models.py 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

Best way to upload image from Mobile to Django server [closed]

喜夏-厌秋 提交于 2019-12-21 21:43:36
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am created a Mobile application(in Titanmium).where user take pictures in mobile and i need To upload the image from mobile to django server .I am using tastypie for my Api can any one guide me the best way to upload and save the image in server the methods may be in pure django

Django Tastypie throws a 'maximum recursion depth exceeded' when full=True on reverse relation.

[亡魂溺海] 提交于 2019-12-21 12:33:08
问题 I get a maximum recursion depth exceeded if a run the code below: from tastypie import fields, utils from tastypie.resources import ModelResource from core.models import Project, Client class ClientResource(ModelResource): projects = fields.ToManyField( 'api.resources.ProjectResource', 'project_set', full=True ) class Meta: queryset = Client.objects.all() resource_name = 'client' class ProjectResource(ModelResource): client = fields.ForeignKey(ClientResource, 'client', full=True) class Meta: