From eb0043d2e6b6bde68a5b53e187e5b91ef22aa04b Mon Sep 17 00:00:00 2001 From: Mihai Date: Tue, 17 Jun 2014 14:27:43 +0300 Subject: [PATCH] replace JSONField in models with a TextField for PostgreSQL PostgreSQL is giving error: could not identify an equality operator for type json This bug report is about the issue: https://github.com/bradjasper/django-jsonfield/issues/47 --- introsite/futuintro/models.py | 5 ++--- introsite/futuintro/tasksched.py | 8 +++++--- introsite/futuintro/views.py | 2 +- req.txt | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/introsite/futuintro/models.py b/introsite/futuintro/models.py index 6ec9e30..3c2f678 100644 --- a/introsite/futuintro/models.py +++ b/introsite/futuintro/models.py @@ -1,7 +1,6 @@ from django.conf import settings from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.db import models -from jsonfield import JSONField class FutuUserManager(BaseUserManager): @@ -151,7 +150,7 @@ class SchedulingRequest(models.Model): """ # the JSON format is documented in views.createSchedules - json = JSONField() + json = models.TextField() requestedBy = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.SET_NULL) requestedAt = models.DateTimeField(auto_now_add=True) @@ -195,7 +194,7 @@ class Event(models.Model): It may belong to several Schedules (e.g. a collective event). """ - json = JSONField() + json = models.TextField() schedules = models.ManyToManyField(Schedule) # Be able to group events by the template they came from (e.g. you didn't diff --git a/introsite/futuintro/tasksched.py b/introsite/futuintro/tasksched.py index 0926d92..3fdcdd4 100644 --- a/introsite/futuintro/tasksched.py +++ b/introsite/futuintro/tasksched.py @@ -127,7 +127,7 @@ def makeEventTasks(): try: UM = get_user_model() schedReq = SchedulingRequest.objects.get(id=modelId) - body = schedReq.json + body = json.loads(schedReq.json) schedTempl = ScheduleTemplate.objects.get( id=body['scheduleTemplate']) schedules = makeSchedules() @@ -170,7 +170,8 @@ def processEventTask(modelId): evTask.summary, evTask.description, locTxt, evTask.startDt, evTask.endDt, schedTempl.timezone.name, attendingEmails) - newEv = Event.objects.create(json=gCalJson, template=evTask.template) + newEv = Event.objects.create(json=json.dumps(gCalJson), + template=evTask.template) newEv.schedules.add(*schedules) except: logging.error(traceback.format_exc()) @@ -208,7 +209,8 @@ def processCleanupSchedulingRequest(modelId): for event in schedule.event_set.all(): sleepForRateLimit() try: - calendar.deleteEvent(calendar.futuintroCalId, event.json['id']) + calendar.deleteEvent(calendar.futuintroCalId, + json.loads(event.json)['id']) except: logging.error(traceback.format_exc()) event.delete() diff --git a/introsite/futuintro/views.py b/introsite/futuintro/views.py index 9288c34..34cf181 100644 --- a/introsite/futuintro/views.py +++ b/introsite/futuintro/views.py @@ -63,7 +63,7 @@ def createSchedules(request): if request.method == 'POST': schedReq = models.SchedulingRequest.objects.create( - json=json.load(request), + json=json.dumps(json.load(request)), requestedBy=request.user, status=models.SchedulingRequest.IN_PROGRESS) tasksched.enqueue(tasksched.SCHED_REQ, schedReq.id) diff --git a/req.txt b/req.txt index 5016032..e9a72b7 100644 --- a/req.txt +++ b/req.txt @@ -6,4 +6,3 @@ gdata python-dateutil pytz django-extensions -jsonfield