Ticket #2443: durationfield.diff

File durationfield.diff, 1009 bytes (added by Marty Alchin <gulopine@…>, 18 years ago)

DurationField

  • django/db/models/fields/__init__.py

     
    571571        defaults.update(kwargs)
    572572        return forms.DateTimeField(**defaults)
    573573
     574class DurationField(FloatField):
     575
     576    def __init__(self, *args, **kwargs):
     577        super(DurationField, self).__init__(max_digits=20, decimal_places=6)
     578
     579    def get_internal_type(self):
     580        return "FloatField"
     581
     582    def to_python(self, value):
     583        try:
     584            return datetime.timedelta(seconds=value)
     585        except TypeError:
     586            raise validators.ValidationError('This value must be a real number.')
     587        except OverflowError:
     588            raise validators.ValidationError('The maximum allowed value is %s' % datetime.timedelta.max)
     589
    574590class EmailField(CharField):
    575591    def __init__(self, *args, **kwargs):
    576592        kwargs['maxlength'] = 75
Back to Top