Skip to content

Commit

Permalink
replace JSONField in models with a TextField for PostgreSQL
Browse files Browse the repository at this point in the history
PostgreSQL is giving error:
could not identify an equality operator for type json

This bug report is about the issue:
rpkilby/jsonfield#47
  • Loading branch information
Mihai committed Jun 26, 2014
1 parent 0aa38f5 commit eb0043d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions introsite/futuintro/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions introsite/futuintro/tasksched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion introsite/futuintro/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion req.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ gdata
python-dateutil
pytz
django-extensions
jsonfield

0 comments on commit eb0043d

Please sign in to comment.