| 691 | class DurationField(FloatField): |
| 692 | |
| 693 | def __init__(self, *args, **kwargs): |
| 694 | super(DurationField, self).__init__(max_digits=20, decimal_places=6) |
| 695 | |
| 696 | def get_internal_type(self): |
| 697 | return "FloatField" |
| 698 | |
| 699 | def to_python(self, value): |
| 700 | print "to_python: %r" % value |
| 701 | try: |
| 702 | return datetime.timedelta(seconds=value) |
| 703 | except TypeError: |
| 704 | raise validators.ValidationError('This value must be a real number.') |
| 705 | except OverflowError: |
| 706 | raise validators.ValidationError('The maximum allowed value is %s' % datetime.timedelta.max) |
| 707 | |
| 708 | |