tastypie

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

心不动则不痛 提交于 2019-12-04 05:43:26
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(*args, **kwargs) def as_leaf_class(self): model = self.content_type.model_class() if model == self._

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

前提是你 提交于 2019-12-04 04:25:57
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: queryset = Project.objects.all() resource_name = 'project' # curl http://localhost:8000/api/client/

Deleting objects in django tastypie

烂漫一生 提交于 2019-12-04 01:42:35
问题 I have the following models: class Poster(models.Model) user = models.OneToOneField(User, primary=True) userpicture = models.CharField(max_length = 128 =True) class Posts(models.Model) poster = models.ForeignKey(Poster, related_name = 'post_owner') url = models.CharField(max_length = 128) time = models.DateTimeField(auto_now_add=True) class Comment(models.Model): user = models.ForeignKey(Poster) post = models.ForeignKey(Posts) time = models.DateTimeField(auto_now_add=True) comment = models

Download anchor link with authorization header

别来无恙 提交于 2019-12-03 22:32:22
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: gunicorn/18.0 Date: Tue, 06 May 2014 03:09:02 GMT Connection: close Transfer-Encoding: chunked Vary: Accept

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

断了今生、忘了曾经 提交于 2019-12-03 21:27:38
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' queryset = Collection.objects.all() filtering = { 'name': ['exact'], 'photos': ALL } class PhotoResource

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

大城市里の小女人 提交于 2019-12-03 17:21:48
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? 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(self, request, **kwargs): try: obj = self.cached_obj_get(request=request, **self.remove_api_resource_names

Tastypie Negation Filter

半城伤御伤魂 提交于 2019-12-03 16:25:21
问题 Is there a negation filter available by default. The idea is that you can do the following in the django ORM: model.objects.filter(field!=value) How can I do that in tastypie if that is even possible. I tried: someapi.com/resource/pk/?field__not=value someapi.com/resource/pk/?field__!=value someapi.com/resource/pk/?field!=value And all of them given me errors. 回答1: Unfortunately there's not. The problem is that Tastypie's ModelResource class uses the filter() method of the QuerySet only, i.e.

How to sign-in? Django TastyPie with ApiKeyAuthentication actual authentication Process

前提是你 提交于 2019-12-03 16:09:52
I have an Adobe Air mobile application that communicates with Django via TastyPie. To use the app people have to register first. Therefore they have to supply their email and password. Afterwards they will be able to "login". I thought it would be the best idea that after entering a successful username/password combination, the api-key will be sent back to the mobile app where it will be cached, so the user is "logged in". Please tell me if you think there is a better way for registering and "logging in" users. Inside Django I have a UserRessource class that I use to register new users when

Using tastypie resource in view

最后都变了- 提交于 2019-12-03 16:08:33
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 for my models : class ChatMessage(models.Model): content = models.TextField() added = models

How to change status of JsonResponse in Django

孤人 提交于 2019-12-03 14:21:11
问题 My API is returning a JSON object on error but the status code is HTTP 200 : response = JsonResponse({'status': 'false', 'message': message}) return response How can I change the response code to indicate an error? 回答1: JsonResponse normally returns HTTP 200 , which is the status code for 'OK' . In order to indicate an error, you can add an HTTP status code to JsonResponse as it is a subclass of HttpResponse : response = JsonResponse({'status':'false','message':message}, status=500) 回答2: