api - Best way to serialize Django-nonrel + MongoDb queries for exchanging with mobile devices? -


i want exchange information between django-nonrel+mongodb , mobile devices via http. when mobile device makes request api, django view executes query, , respond serialization of query results.

my problem django's built-in serialization formats don't play models containing embedded aggregates , lists. work around not using these no-sql features, nullify motivation using mongodb in first place.

what best way serialize data mongodb query?

i know can import bson , use "encode" , "decode" functions, seem work on dictionaries. current inelegant view test code makes cumbersome embedded dictionary structure underlying model:

def get_announcements(request):   """   return bson representation of ten recent announcements relevant   user.   """   user = user.objects.get(username='*<somebody>*') # test user   campaign_announcements = campaign.objects.filter(workers=user.id)[:10]   data = {}   campaign in campaign_announcements:     data[campaign.name] = []     announcement in campaign.announcements:       data[campaign.name].append({           'tagline': announcement.tagline,           'content': announcement.content,           'release_time': announcement.release_time,         })   return httpresponse(bson.encode(data)) 

i able this:

return httpresponse(serializers.serialize("bson", <query>)) 

this assumes bson format ought use. i'm assuming because it's mongodb's default format.

responses other questions mention pymongo's json_util submodule. looked @ it, don't think i'm trying do.

thanks!

update 20 august 2013: responded question. decided abandon no-sql. seems interesting , useful technology, doesn't seem play environment: django, heroku, , android. getting embedded objects serialize in useful manner seems take bunch of hacking rather avoid, , android uses sqlite, have convert serialized data schema anyways.

try looking django-tastypie. it's got built in serializers, , it's rest api querying based on django models.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -