Matthew Schinckel  committed 4279ab6

Make it easier to add column types for different databases.
Added column type="INTERVAL" for postgis. Resolves #3.

  • Participants
  • Parent commits 1c36489
  • Branches default
  • Tags 0.4.6

Comments (0)

Files changed (1)

File timedelta/

 from django.db import models
+from collections import defaultdict
 import datetime
 from helpers import parse
 # TODO: Figure out why django admin thinks fields of this type have changed every time an object is saved.
+# Define the different column types that different databases can use.
+COLUMN_TYPES = defaultdict(lambda:"char(20)")
+COLUMN_TYPES["django.db.backends.postgresql_psycopg2"] = "interval"
+COLUMN_TYPES["django.contrib.gis.db.backends.postgis"] = "interval"
 class TimedeltaField(models.Field):
     Store a datetime.timedelta as an INTERVAL in postgres, or a 
         return ""
     def db_type(self, connection):
-        """
-        Postgres allows us to store stuff as an INTERVAL type. This is 
-        useful, and we can then use database logic to do tests.
-        """
-        if connection.settings_dict['ENGINE'] == "django.db.backends.postgresql_psycopg2":
-            return 'interval'
-        else:
-            return 'char(20)'
+        return COLUMN_TYPES[connection.settings_dict['ENGINE']]