Monday, August 19, 2013

Writing a django json propery serializer

Writing a django json PROPERTY serializer.

So, what's up? This will be my first blog post in english, and for the rest of my writing here in this blog that the language i'll use. The main reason is because most of the traffic that is coming here is from people outside my home land (which is Brazil).

Anyway, this blog post is about the django framework, well not exactly the framework itself but a little part that i use daily.
But before the code! A little background showing the why i did this...

Most of my time i use PHP as my main programming language to write web software (not that i like that, but anyway... i have to). Right at the beginning we (means me and my coworkers) start using Zend Framework to write our web apps, and we return JSON strings as part of the response. Simply because we used ExtJs togheter! Pretty slick at that time, but also pretty heavy (ok, not that much).
Since then i've been learn more and more about python e django to the point that they bacame my main programming language (and framework, off course) used to make my hobbiest projects! :D

So, there came the need of write my own JsonSerializer, because django default serializer don't serialize propertys... for me, propertys are a way to enhance the data viewed by a user inside a grid.
Nowdays i dont use anymore ExtJs (perhaps ill use in future projects), but i build my own jquery grid! (ill put this code on github, since i make some cleanup!) But this little grid jquery plugin still eat up JSON as the main format.

And that's why i change the default JsonSerializer and made this PropertyJsonSerializer!
Anyway... here's the fucking code! And if you dear reader find any bugs on this... write that up on the comments or use the gist tool...

thanks a lot!


Post a Comment