Django's serializer has some limitations which makes it a bit of a pain to use. Basically it will ignore any atributes that have been added to a model object.
The code below is for an alternative serializer. This version allows you select what attributes will be serialized on a per object basis. It also allows you to either serialize the data into json or xml. This code also works if you have model instance as an attribute of another model.
You can get the code on django snippets.
The original json encoder was written by Wolfram Kriesing.
Usage:
dumper = DataDumper()
dumper.selectObjectFields('model_class_name',[...fields...])
dumper.selectObjectFields('model_class_name',[...fields...])
dumper.dump(model_instance,'xml')
dumper.dump(model_instance,'json')
dumper.dump(queryset,'xml')




Comments
Bratislava Stag
If you're building a resource-driven app, chances are you'll have views that map closely to Django models. For instance, you might have a Post model, and you want to create views that lets people interact with this resource. In this case, it would be redundant to define create, retrieve, update and delete functions in your views again and again.
re
I opine that to receive the credit loans from banks you ought to present a great reason. However, one time I've got a short term loan, because I was willing to buy a bike.
Barcode Tag Creator
If we lost important messages, contact numbers, music songs, snapshots and videos from iPhone then how can we recover lost data from iPhone?
Term Papers
Thanks for the tip! I've used it on my blog now.
review
Such a nice post, it is really interesting,you are really a hard worker guy, Thanks.
iphone alternative
It's a shame that not many people know that there ARE alternatives to the iphone out there. You can pick up a good iphone alternative for under $100 and even under $50 ! Add to that the fact you can get free apps and you are pretty much laughing all the way to the bank !
Post new comment