Skip to content

Commit

Permalink
Migrate JSONField
Browse files Browse the repository at this point in the history
  • Loading branch information
Szaki committed Apr 24, 2024
1 parent ec3cd6a commit 57ae8b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions binder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django import forms
from django.db import models
from django.db.models.fields.files import FieldFile, FileField
from django.contrib.postgres.fields import CITextField, ArrayField, JSONField, DateTimeRangeField as DTRangeField
from django.contrib.postgres.fields import CITextField, ArrayField, DateTimeRangeField as DTRangeField
from django.core import checks
from django.core.files.base import File, ContentFile
from django.core.files.images import ImageFile
Expand Down Expand Up @@ -395,7 +395,7 @@ def clean_value(self, qualifier, v):


class JSONFieldFilter(FieldFilter):
fields = [JSONField]
fields = [models.JSONField]
# TODO: Element or path-based lookup is not supported yet
allowed_qualifiers = [None, 'contains', 'contained_by', 'has_key', 'has_any_keys', 'has_keys', 'isnull']

Expand Down
16 changes: 16 additions & 0 deletions binder/plugins/my_filters/migrations/0002_migrate_jsonfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('my_filters', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='MyFilter',
name='params',
field=models.JSONField(),
),
]
3 changes: 1 addition & 2 deletions binder/plugins/my_filters/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.contrib.postgres.fields import JSONField
from django.conf import settings

from ...models import BinderModel
Expand All @@ -13,7 +12,7 @@ class MyFilter(BinderModel):
)
view = models.TextField()
name = models.TextField()
params = JSONField()
params = models.JSONField()
default = models.BooleanField(default=False)

class Meta(BinderModel.Meta):
Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/models/feeding_schedule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.postgres.fields import ArrayField, JSONField
from django.contrib.postgres.fields import ArrayField
from django.db import models
from binder.models import BinderModel, ChoiceEnum

Expand All @@ -8,7 +8,7 @@ class FeedingSchedule(BinderModel):
animal = models.OneToOneField('Animal', on_delete=models.CASCADE, related_name='feeding_schedule')
description = models.TextField(blank=True, null=True)
foods = ArrayField(models.TextField(choices=FOODS.choices()), blank=True, default=[])
schedule_details = JSONField(blank=True, default=[])
schedule_details = models.JSONField(blank=True, default=[])

def __str__(self):
return 'feeding schedule %d: %s (for %s)' % (self.pk, self.description, self.animal)

0 comments on commit 57ae8b3

Please sign in to comment.