My Python & co. stuff

Archive for the ‘Django’ Category

… and settings.py, and urls.py, and so on. Customize as you like.

 

from django.conf import settings
from django.core import management

MY_APP = '' # Your app name here
if not MY_APP_NAME:
    import sys
    MY_APP_NAME = sys.argv[1]

settings.configure(
    DEBUG=True, 
    TEMPLATE_DEBUG=True,
    INSTALLED_APPS = [MY_APP],
    DATABASES = {
        'default': {
            'ENGINE':'django.db.backends.sqlite3',
            'NAME': ':memory:',
            }
        }
    )

management.call_command('test', MY_APP)
Advertisements

UPDATE: There is a Google Code project on django+postgresql+INTERVAL available here.

Here you are. Idea taken from zboczuch:

from datetime import timedelta
from django.conf import settings

class IntervalField(models.Field):

    def db_type(self):
        if not settings.DATABASE_ENGINE.startswith('postgresql'):
            raise NotImplementedError
        return "interval"

    def to_python(self, value):
        assert(isinstance(value, timedelta))
        return value

    def _seconds(self, value):
        return value.days * 24 * 60 * 60 + value.seconds + (value.microseconds / 1000000.0)

    def get_db_prep_value(self, value):
        if value is None: return None
        return '%f' % self._seconds(value)