Tastypie: How can I populate a resource without a database?

I want to get some information from Foursquare, add some fields and return them through django-tastypie. UPDATE:

def obj_get_list(self, request=None, **kwargs): near = '' if 'near' in request.GET and request.GET['near']: near = request.GET['near'] if 'q' in request.GET and request.GET['q']: q = request.GET['q'] client = foursquare.Foursquare(client_id=settings.FSQ_CLIENT_ID, client_secret=settings.FSQ_CLIENT_SECRET) a = client.venues.search(params={'query': q, 'near' : near, 'categoryId' : '4d4b7105d754a06374d81259' }) objects = [] for venue in a['venues']: bundle = self.build_bundle(obj=venue, request=request) bundle = self.full_dehydrate(bundle) objects.append(bundle) return objects 

Now I get:

 { "meta": { "limit": 20, "next": "/api/v1/venue/?q=Borek&near=Kadikoy", "offset": 0, "previous": null, "total_count": 30 }, "objects": [ { "resource_uri": "" }, { "resource_uri": "" }] } 

There are two empty objects. What to do to fill this resource?

+6
source share
1 answer

ModelResource is only suitable when you have an ORM model behind a resource. In other cases, you should use Resource .

This issue is discussed in the ModelResource description, indicating when it fits and when not: http://django-tastypie.readthedocs.org/en/latest/resources.html#why-resource-vs-modelresource

The documentation also contains an entire chapter, the purpose of which is to provide information on how to implement data sources other than ORM (in this case, an external API): http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources. html

+9
source

Source: https://habr.com/ru/post/928042/


All Articles