Skip to content

Commit

Permalink
Add date/datetime types support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Antukh committed Jan 8, 2014
1 parent 9018d0f commit 5e67761
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions djorm_pgarray/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
'text': str,
'double precision': float,
'varchar': str,
'date': lambda x: x,
'datetime': lambda x: x,
}


Expand Down
9 changes: 9 additions & 0 deletions testing/pg_array_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class MultiTypeModel(models.Model):
varchars = ArrayField(dbtype="varchar(30)")
objects = ExpressionManager()

class DateModel(models.Model):
dates = ArrayField(dbtype="date")
objects = ExpressionManager()


class DateTimeModel(models.Model):
dates = ArrayField(dbtype="timestamp")
objects = ExpressionManager()


class ChoicesModel(models.Model):
choices = ArrayField(dbtype='text', choices=[('A', 'A'), ('B', 'B')])
19 changes: 19 additions & 0 deletions testing/pg_array_fields/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

import datetime

from django.contrib.admin import AdminSite, ModelAdmin
from django.core.serializers import serialize, deserialize
from django.db import connection
Expand All @@ -16,6 +18,8 @@
MultiTypeModel,
ChoicesModel,
Item,
DateModel,
DateTimeModel,
ArrayExpression,
MacAddrModel)

Expand Down Expand Up @@ -79,6 +83,21 @@ def test_subquery(self):
qs2 = Item.objects.filter(id__in=qs1.values('id'))
# print(qs2.query.__str__())

def test_date(self):
d = datetime.date(2011, 11, 11)
instance = DateModel.objects.create(dates=[d])

instance = DateModel.objects.get(pk=instance.pk)
self.assertEqual(instance.dates[0], d)


def test_datetime(self):
d = datetime.datetime(2011, 11, 11, 11, 11, 11)
instance = DateTimeModel.objects.create(dates=[d])
instance = DateTimeModel.objects.get(pk=instance.pk)
self.assertEqual(instance.dates[0], d)


def test_empty_create(self):
instance = IntModel.objects.create(lista=[])
instance = IntModel.objects.get(pk=instance.pk)
Expand Down

0 comments on commit 5e67761

Please sign in to comment.