inherit from jsonbfield package not jsonfield

* jsonbfield supports json querying. jsonfield package is still a jsonb
postgres data type, but doesn't support jsonb style querying.
* add undo migration support to GIN index
This commit is contained in:
Chris Meyers 2017-04-05 11:11:46 -04:00
parent f7fb541fe2
commit 02795e526c
3 changed files with 10 additions and 5 deletions

View File

@ -27,6 +27,7 @@ from django.db.models import Q
# Django-JSONField
from jsonfield import JSONField as upstream_JSONField
from jsonbfield.fields import JSONField as upstream_JSONBField
# AWX
from awx.main.models.rbac import batch_role_ancestor_rebuilding, Role
@ -47,7 +48,7 @@ class JSONField(upstream_JSONField):
return super(JSONField, self).from_db_value(value, expression, connection, context)
class JSONBField(upstream_JSONField):
class JSONBField(upstream_JSONBField):
def get_db_prep_value(self, value, connection, prepared=False):
if connection.vendor == 'sqlite':
# sqlite (which we use for tests) does not support jsonb;
@ -399,8 +400,10 @@ class DynamicFilterField(models.TextField):
last_v = new_v
last_kv = new_kv
contains_count += 1
if contains_count > 1:
if contains_count == 1 and isinstance(assembled_v, basestring):
assembled_v = '"' + assembled_v + '"'
elif contains_count > 1:
if type(last_v) is list:
last_v.append(v)
if type(last_v) is dict:

View File

@ -39,5 +39,6 @@ class Migration(migrations.Migration):
index_together=set([('timestamp', 'module', 'host')]),
),
migrations.RunSQL([("CREATE INDEX fact_recent_facts_default_gin ON %s USING gin"
"(facts jsonb_path_ops);", [AsIs(FactRecent._meta.db_table)])]),
"(facts jsonb_path_ops);", [AsIs(FactRecent._meta.db_table)])],
[('DROP INDEX fact_recent_facts_default_gin;', None)]),
]

View File

@ -59,7 +59,8 @@ class TestDynamicFilterFieldFilterStringToQ():
('a__b__c[]=3.14', Q(**{ "a__b__c__contains": 3.14})),
('a__b__c[]=true', Q(**{ "a__b__c__contains": True})),
('a__b__c[]=false', Q(**{ "a__b__c__contains": False})),
('a__b__c[]="true"', Q(**{ "a__b__c__contains": "true"})),
('a__b__c[]="true"', Q(**{ "a__b__c__contains": "\"true\""})),
('a__b__c[]="hello world"', Q(**{ "a__b__c__contains": "\"hello world\""})),
('a__b__c[]__d[]="foobar"', Q(**{ "a__b__c__contains": [{"d": ["foobar"]}]})),
('a__b__c[]__d="foobar"', Q(**{ "a__b__c__contains": [{"d": "foobar"}]})),
('a__b__c[]__d__e="foobar"', Q(**{ "a__b__c__contains": [{"d": {"e": "foobar"}}]})),