Search code examples
pythondjangopython-2.7django-1.4

How to store data pairs in django without an extra model?


I want to create an app that stores bills for me. Since I don't have fixed prices for anything there is no need to store my services in an extra model. I just want to store data pairs of "action" and "price" to print them out nicely in a table.

Is there something in django that can help me with that task or should I just put all data pairs together in a textfield and explode it every time i want to use it ?

The number of data pairs per bill is not fixed. Data pairs are used only in one bill, so i don't want an extra table.


Solution

  • Instead of a plain TextField you should look at field types that are better suited for storing structured data: In addition to Acorn's suggestion (django-hstore) a JsonField or a PickleField might be suitable (and more portable) solutions for your use case.