Soham Navadiya
Soham Navadiya

Reputation: 403

How to create key value data type in django 1.7 models

I want to store key-value pair in one column.

Above >Django-1.7 provides hstore to do that.

But I want to same functionality in Django-1.7.

How can I create custom datatype to store key-value pair in one column.

I am using postgres-9.5 database.

I want to store below json in key value pair in one column.

Example:

{
    "prepared_date":"2016-08-08T02:04:34Z",
    "date_0":"2016-08-08T02:04:34Z",
    "status_0":true,
    "date_1":"2016-08-08T02:04:34Z",
    "status_1":true,
    "date_2":"2016-08-08T02:04:34Z",
    "status_2":true,
}

Upvotes: 1

Views: 1261

Answers (1)

There's a nice package exactly for this purpose:

http://djangonauts.github.io/django-hstore/

So just install using pip:

pip install django-hstore

Upvotes: 4

Related Questions