Changeset 536

Show
Ignore:
Timestamp:
02/11/10 14:03:12 (6 months ago)
Author:
olivier
Message:

store durations as integers for compatibility with Django mysql backend

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/telemeta/models/core.py

    r534 r536  
    145145 
    146146    default_error_messages = { 
    147         'invalid': _('Enter a valid duration in HH:MM[:ss[.uuuuuu]] format.'), 
     147        'invalid': _('Enter a valid duration in HH:MM[:ss] format.'), 
    148148    } 
    149149 
     
    151151        super(DurationField, self).__init__(*args, **normalize_field(kwargs, '00:00')) 
    152152 
    153     def get_internal_type(self): 
    154         return 'TimeField' 
     153    def db_type(self): 
     154        return 'int' 
    155155 
    156156    def to_python(self, value): 
    157157        if value is None: 
    158158            return None 
     159        if isinstance(value, int) or isinstance(value, long): 
     160            return Duration(seconds=value) 
    159161        if isinstance(value, datetime.time): 
    160162            return Duration(hours=value.hour, minutes=value.minute, seconds=value.second) 
     
    175177    def get_db_prep_value(self, value, connection, prepared=False): 
    176178        # Casts times into the format expected by the backend 
    177         return unicode(value) 
     179        return value.as_seconds() 
    178180 
    179181    def value_to_string(self, obj):