Matthew Schinckel avatar Matthew Schinckel committed 4279ab6

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

Comments (0)

Files changed (1)


 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']]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.