[Debconf-video-commits] r348 - package/branches/pycon09/src/debconfvideo/web/pyconvideo
benh at alioth.debian.org
benh at alioth.debian.org
Sat Mar 21 03:58:27 UTC 2009
Author: benh
Date: 2009-03-21 03:58:27 +0000 (Sat, 21 Mar 2009)
New Revision: 348
Modified:
package/branches/pycon09/src/debconfvideo/web/pyconvideo/models.py
Log:
Implement IntervalField properly.
Modified: package/branches/pycon09/src/debconfvideo/web/pyconvideo/models.py
===================================================================
--- package/branches/pycon09/src/debconfvideo/web/pyconvideo/models.py 2009-03-20 14:24:41 UTC (rev 347)
+++ package/branches/pycon09/src/debconfvideo/web/pyconvideo/models.py 2009-03-21 03:58:27 UTC (rev 348)
@@ -1,11 +1,26 @@
# Based on auto-generated Django model code.
from django.db import models
+import mx.DateTime
-class IntervalField(models.TextField):
- # TODO
- pass
+def hms_to_seconds(hms):
+ parts = hms.split(':')
+ if len(parts) > 3:
+ raise ValueError()
+ hours, minutes, seconds = (3 - len(parts)) * [0] + parts
+ return (int(hours) * 60 + int(minutes)) * 60 + float(seconds)
+class IntervalField(models.CharField):
+ def __init__(self, *args, **kwargs):
+ kwargs['max_length'] = 12
+ super(IntervalField, self).__init__(*args, **kwargs)
+ def db_type(self):
+ return 'INTERVAL'
+ def to_python(self, value):
+ return value
+ def get_db_prep_value(self, value):
+ return '%g SECONDS' % hms_to_seconds(value)
+
class Conference(models.Model):
conference_id = models.AutoField(primary_key=True)
title = models.CharField(unique=True, max_length=200)
More information about the Debconf-video-commits
mailing list