tastypie

Exposing model method with Tastypie

≡放荡痞女 提交于 2019-12-31 09:59:30
问题 I am currently working on implementing an API into my Django project and Tastypie seemed like it would be most suitable. What I can't seem to work out is how to expose a function within my model using Tastypie. For example, I have this model: class game(models.Model): id = models.AutoField("ID", primary_key=True, editable=False) ip_address = models.OneToOneField(IPAddress, verbose_name="IP Address") port = models.CharField("Port", max_length=5) name = models.CharField("Game Name", max_length

get request parameters in Tastypie

佐手、 提交于 2019-12-30 07:07:46
问题 I am building a REST API for my application that uses a NoSQL db (Neo4j) using Tastypie. So I overrode some main methods of the class tastypie.resources.Resource to do so, and currently struggling to implement def obj_get_list(self, request=None, **kwargs): which is supposed to return a list of objects. Actually, I want to pass a parameter to this method through the url (something like http://127.0.0.1:8000/api/airport/?query='aQuery' ) and then perform a query based on this parameter. The

'Request header field Authorization is not allowed' error - Tastypie

泪湿孤枕 提交于 2019-12-30 03:41:05
问题 I am getting the following error while using ApiKeyAuthentication for my Tastypie resources when I try to do an HTTP request using AJAX and Tastypie: XMLHttpRequest cannot load http://domain.com/api/v1/item/?format=json&username=popo&api_key=b83d21e2f8bd4952a53d0ce12a2314c0ffa031b1. Request header field Authorization is not allowed by Access-Control-Allow-Headers. Any ideas on how to solve this? Here are the request headers from Chrome: Request Headersview source Accept:*/* Accept-Charset:

Integration of RestKit with Django-Tastypie

孤街醉人 提交于 2019-12-25 04:05:45
问题 This is my first project using RestKit and I am trying to make my simple iOS application synchronize with a set of API served by a Django application using the Tastypie package. My iOS application is based on the Core Data Default Xcode application. I'm trying to retrieve objects from a simple model : Car (name (string), public (boolean), id (integer), created (datetime)) My API looks like that for collections : http://www.example.com/api/v1/car/?format=json {"meta": {"limit": 20, "next":

How to convert a Django model instance to JSON using existing Tastypie Resource?

ぃ、小莉子 提交于 2019-12-25 00:28:51
问题 This problem is related to this other problem, but instead, I wish to convert a single model instance to JSON, using an existing Tastypie Resource. 回答1: Thanks to @grimygoop for the hint, I managed to create a method that can serialize any Django model instance to JSON using the associated Tastypie Resource. Here's how the procedure works... def res_serialize(request, resource, obj): data = resource.full_dehydrate(resource.build_bundle(obj=obj, request=request)) return resource.serialize(None

Finding most popular tag Taggit Tastypie Django

余生颓废 提交于 2019-12-24 07:18:07
问题 Context I have been having conflict. Currenly, I am creating a question answer application. Each question has a tag, and I want to show the most popular tags (e.g. tags that have the most questions associated with it). Specifics I am using django-taggit 's TaggableManager to do so. Here is the model definition of the Question : class Question(models.Model): tags = TaggableManager() date = models.DateTimeField(default=timezone.now) text = models.TextField(null=True) So now I have the several

Retrieving images from GridFS using django-tastypie-mongoengine

前提是你 提交于 2019-12-24 03:42:48
问题 I have a project in Django, and I'm using mongoengine to save images into a Mongo database using GridFSStorage. All ok so far, but the problem is... when trying to retrieve the images via http request, with a REST API made with django-tastypie-mongoengine, I get back a json object like this: {"file": "<GridFSProxy: 516ed7cf56ba7d01eb09f522>", "id": "516ed7cf56ba7d01eb09f524", "resource_uri": "/api/v1/pic/516ed7cf56ba7d01eb09f524/"} Does anybody know how could I get the file from GridFS via

page() takes 1 positional argument but 2 were given

北战南征 提交于 2019-12-24 01:44:58
问题 I am trying to design an api for search functionality. Search is based on place name.What i want is localhost:8000/api/v1/rent/search/?format=json&q="california" but i am getting an error which i have attached below { "error_message": "page() takes 1 positional argument but 2 were given", "traceback": "Traceback (most recent call last):\n\n File \"/home/tushant/.virtualenvs/rent/lib/python3.4/site-packages/tastypie/resources.py\", line 211, in wrapper\n response = callback(request, *args, *

TastyPie and Django authorization with ApiKeyAuthentication

≡放荡痞女 提交于 2019-12-23 23:37:25
问题 I've been struggling with this for a bit, pouring over a bunch of other SO answers but can't seem to figure out how to authenticate a user to my Django site using the ApiKeyAuthentication. In this answer the accepted answer states "Add the username and api_key parameters to your GET variables". My question is, how do I know what the api key is, if TastyPie is generating the key for me? If I wanted to create my own key, where would I put that key? Here's my api.py: class SystemResource

tastypie won't remove foreignkey reference during PUT

﹥>﹥吖頭↗ 提交于 2019-12-23 18:36:10
问题 I'm having an issue with Tastypie not saving changes to my object when I do a PUT that causes a foreignkey field to be set to null. Here's my ModelResource: class FolderResource(ModelResource): parent = fields.ForeignKey('self','parent',full=True,default=None,blank=True,null=True) project = fields.ForeignKey(ProjectResource,'project',full=False) class Meta: queryset = Folder.objects.all() authentication = Authentication() authorization = Authorization() resource_name = 'folder' include