add model fact recent

* Copy of the most recent system tracking fact for each module type.
Utimately, this allows us to GIN index the jsonb object to support
fact searching.
This commit is contained in:
Chris Meyers
2017-04-04 16:32:30 -04:00
parent cc476541a1
commit f5d7d0bce5
3 changed files with 96 additions and 2 deletions
+17
View File
@@ -5,6 +5,7 @@
import json
import re
import sys
import six
from pyparsing import infixNotation, opAssoc, Optional, Literal, CharsNotIn
# Django
@@ -45,6 +46,22 @@ class JSONField(upstream_JSONField):
return {}
return super(JSONField, self).from_db_value(value, expression, connection, context)
class JSONBField(upstream_JSONField):
def get_db_prep_value(self, value, connection, prepared=False):
if connection.vendor == 'sqlite':
# sqlite (which we use for tests) does not support jsonb;
return json.dumps(value)
return super(JSONBField, self).get_db_prep_value(
value, connection, prepared
)
def from_db_value(self, value, expression, connection, context):
# Work around a bug in django-jsonfield
# https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos
if isinstance(value, six.string_types):
return json.loads(value)
return value
# Based on AutoOneToOneField from django-annoying:
# https://bitbucket.org/offline/django-annoying/src/a0de8b294db3/annoying/fields.py