tastypie

DataTables: Custom Response Handling

帅比萌擦擦* 提交于 2019-11-28 19:13:17
问题 I started working on AngularJS and DataTables and wonder whether it is possible to customize the response DataTables is expecting. The current expectation of the DataTables plugin is something like this: { "draw": 1, "recordsTotal": 57, "recordsFiltered": 5, "data": [...] } On the server end, the API's are being handled by django-tastypie The response from server is: { meta: { limit: 20, next: null, offset: 0, previous: null, total_count: 2 }, objects: [...] } So, is there a way to tweak

heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts

喜你入骨 提交于 2019-11-28 09:42:50
I have a simple query on django's built in comments model and getting the error below with heroku's postgreSQL database: DatabaseError: operator does not exist: integer = text LINE 1: ... INNER JOIN "django_comments" ON ("pi ns_pin"."id" = "django_... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. After googling around it seems this error has been addressed many times before in django, but I'm still getting it (all related issues were closed 3-5 years ago) . I am using django version 1.4 and the latest build of tastypie. The query is

How do you upload a file with a POST request on django-tastypie? [duplicate]

℡╲_俬逩灬. 提交于 2019-11-28 07:52:54
Possible Duplicate: Django-tastypie: Any example on file upload in POST? I currently do cURL POST requests to my API like so curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"username":"theusername", "api_key":"anapikey", "video_title":"a title", "video_description":"the description"}' http://localhost:8000/api/v1/video/ but now I need to be able to add a video file to the upload. I have been looking around for a few hours about uploading files with Tastypie and I have not come up with one solid response. Do I need to add the Base64 encode? If so how? How do I acces

How to create or register User using django-tastypie API programmatically?

。_饼干妹妹 提交于 2019-11-28 04:34:30
My code below kinda works, it creates the User object and saves but it doesn't save the password: class CreateUserResource(ModelResource): class Meta: allowed_methods = ['post'] object_class = User authentication = Authentication() authorization = Authorization() include_resource_uri = False fields = ['username'] def obj_create(self, bundle, request=None, **kwargs): try: bundle = super(CreateUserResource, self).obj_create(bundle, request, **kwargs) except IntegrityError: raise BadRequest('That username already exists') return bundle If I add 'password' to the Meta fields then it does save the

Tastypie, add element to a many to many relationship

混江龙づ霸主 提交于 2019-11-28 03:42:26
问题 I'm building a django tastypie api, and I have a problem with adding elements in ManyToMany relationships Example, models.py class Picture(models.db): """ A picture of people""" people = models.ManyToManyField(Person, related_name='pictures', help_text="The people in this picture", ) class Person(models.db): """ A model to represet a person """ name = models.CharField(max_length=200, help_text="The name of this person", ) resources: class PictureResource(ModelResource): """ API Resource for

Django Tastypie not Updating Resource with ManyToManyField

孤街醉人 提交于 2019-11-28 02:26:51
问题 Why doesn't my resource with a ManyToManyField update with this PUT request? curl --dump-header - -H "Content-Type: application/json" -X PUT --data '{"uuid":"blah","pass_token":"blah","favorites": ["/api/v1/organizations/1/"]}' http://localhost:8000/api/v1/devices/2/ I get this response: HTTP/1.0 400 BAD REQUEST Date: Wed, 11 Jul 2012 22:21:15 GMT Server: WSGIServer/0.1 Python/2.7.2 Content-Type: application/json; charset=utf-8 {"favorites": ["\"/api/v1/organizations/1/\" is not a valid value

Tastypie obj_create - how to use newly created object?

余生长醉 提交于 2019-11-28 00:48:41
问题 When a new item is created using Tastypie, I want to be able to add it to a user's attribute which is a many-to-many field. RIght now my obj_create looks like this: def obj_create(self, bundle, request=None, **kwargs): return super(GoalResource, self).obj_create(bundle, request, user=request.user) I want to create the new object, but when I want to be able to add it to the request.user's attribute goal_list. But, what I have will immediately create the object in the database. How would I

Django Tastypie: How to Authenticate with API Key

被刻印的时光 ゝ 提交于 2019-11-27 13:17:39
I'm making an internal API with TastyPie. I have from tastypie.authentication import ApiKeyAuthentication class MyResource(ModelResource): Meta: authentication = ApiKeyAuthentication() With Auth rules disabled, my API works great. With it on, I get a 401 (UNAUTHORIZED) response no matter what I try. I'm sure this is one of those things that's really obvious once you've see it in action, but in the meantime, please advise how to to make the request (a GET). Add the username and api_key parameters to your GET variables. Make sure that you have the curl http://localhost:8000/api/v1/books/

Django Tastypie Advanced Filtering: How to do complex lookups with Q objects

旧城冷巷雨未停 提交于 2019-11-27 12:04:48
I have a basic Django model like: class Business(models.Model): name = models.CharField(max_length=200, unique=True) email = models.EmailField() phone = models.CharField(max_length=40, blank=True, null=True) description = models.TextField(max_length=500) I need to execute a complex query on the above model like: qset = ( Q(name__icontains=query) | Q(description__icontains=query) | Q(email__icontains=query) ) results = Business.objects.filter(qset).distinct() I have tried the following using tastypie with no luck: def build_filters(self, filters=None): if filters is None: filters = {} orm

Django-tastypie: Any example on file upload in POST?

陌路散爱 提交于 2019-11-27 04:15:25
Could anyone give a complete example on using the tastypie FileField, both server-side and client-side please? Here's what I have tried: #models.py class Foo(models.Model): img = models.ImageField(upload_to="images", null=True, blank=True) body = models.CharField() #api.py class FooResource(ModelResource): img = fields.FileField(attribute="image", null=True, blank=True) class Meta: queryset = Foo.objects.all() If I try to create a foo object using curl, e.g., >>> curl -F "body=test" -F "img=@local_img.png" http://localhost:8000/api/0.1/foo/ A foo object is successfully created, but the img