How to Store Arbitrary Data in a Django Model
I have a number of different places where I have wanted to store arbitrary data along with structured data in a Django model. This is data that I wouldn't necessarily care to use a value to retrieve data but when displaying or working with a record or records of this data, being able to have this data available in a manner that I didn't have to parse was nice.
My solution was to serialize/deserialize in and out of JSON using simplejson and a Field class that derives from a TextField. i think it is easier to just read the code and the example of how to use it in the gist below than for me to continue with my rambles.
The Code
UPDATE: It wasn't clear in this post. This wasn't my code, as I had previously pointed out. Just wanted to be clear that I have found this solution useful and have used the snippet so much that I feel like it's mine -- but it's not. :)
Commentary
blog comments powered by Disqus