Skip to content

Commit

Permalink
Merge pull request #123 from Terralego/encode_date_in_json
Browse files Browse the repository at this point in the history
use DjangoJSONEncoder
  • Loading branch information
submarcos authored Mar 6, 2023
2 parents d402e72 + 69f7a60 commit 55419f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
0.7.1+dev (XXXX-XX-XX)
---------------------------

* Allow dates and objects in feature properties by using DjangoJSONEncoder

0.7.1 (2023-03-03)
---------------------------
Expand Down
23 changes: 23 additions & 0 deletions geostore/migrations/0047_alter_feature_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.18 on 2023-03-06 15:54

try:
from django.db.models import JSONField
except ImportError: # TODO Remove when dropping Django releases < 3.1
from django.contrib.postgres.fields import JSONField
import django.core.serializers.json
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('geostore', '0046_auto_20211013_1334'),
]

operations = [
migrations.AlterField(
model_name='feature',
name='properties',
field=JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder, verbose_name='Properties'),
),
]
4 changes: 3 additions & 1 deletion geostore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.gis.db.models import GeometryField
from django.contrib.gis.db.models.functions import Transform
from django.contrib.gis.geos import GEOSGeometry, WKBWriter
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models.functions import Cast

from .import_export.exports import LayerExportMixin
Expand Down Expand Up @@ -174,7 +175,8 @@ class Feature(BaseUpdatableModel, PgRoutingMixin):
verbose_name=_("Identifier"))
properties = JSONField(default=dict,
blank=True,
verbose_name=_("Properties"))
verbose_name=_("Properties"),
encoder=DjangoJSONEncoder)
layer = models.ForeignKey(Layer,
on_delete=models.PROTECT,
related_name='features',
Expand Down

0 comments on commit 55419f2

Please sign in to comment.