use postgres json field
This commit is contained in:
parent
bbaaeb7263
commit
1bac062a50
24 changed files with 284 additions and 45 deletions
22
pandora/changelog/migrations/0002_jsonfield.py
Normal file
22
pandora/changelog/migrations/0002_jsonfield.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2018-06-19 17:23
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.contrib.postgres.fields.jsonb
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('changelog', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(
|
||||
'ALTER TABLE "changelog_changelog" ALTER COLUMN "value" TYPE jsonb USING "value"::text::jsonb'
|
||||
),
|
||||
migrations.RunSQL(
|
||||
'ALTER TABLE "changelog_log" ALTER COLUMN "data" TYPE jsonb USING "data"::text::jsonb'
|
||||
),
|
||||
]
|
||||
|
|
@ -6,8 +6,8 @@ from datetime import datetime
|
|||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from oxdjango.fields import JSONField
|
||||
|
||||
from oxdjango import fields
|
||||
import ox
|
||||
|
||||
import websocket
|
||||
|
|
@ -21,7 +21,7 @@ FIXME: remove this table more migrate to new ChangeLog
|
|||
class Changelog(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
type = models.CharField(max_length=255, db_index=True)
|
||||
value = fields.DictField(default={})
|
||||
value = JSONField(default=dict, editable=False)
|
||||
|
||||
def __str__(self):
|
||||
return u'%s %s' % (self.type, self.created)
|
||||
|
|
@ -52,7 +52,7 @@ def add_changelog(request, data, id=None):
|
|||
class Log(models.Model):
|
||||
|
||||
action = models.CharField(max_length=255, db_index=True)
|
||||
data = fields.DictField(default={})
|
||||
data = JSONField(default=dict, editable=False)
|
||||
created = models.DateTimeField(db_index=True)
|
||||
user = models.ForeignKey(User, null=True, related_name='changelog')
|
||||
changeid = models.TextField()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue