| 574 | class 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 | |