(self, value)
| 2658 | return "TimeField" |
| 2659 | |
| 2660 | def to_python(self, value): |
| 2661 | if value is None: |
| 2662 | return None |
| 2663 | if isinstance(value, datetime.time): |
| 2664 | return value |
| 2665 | if isinstance(value, datetime.datetime): |
| 2666 | # Not usually a good idea to pass in a datetime here (it loses |
| 2667 | # information), but this can be a side-effect of interacting with a |
| 2668 | # database backend (e.g. Oracle), so we'll be accommodating. |
| 2669 | return value.time() |
| 2670 | |
| 2671 | try: |
| 2672 | parsed = parse_time(value) |
| 2673 | if parsed is not None: |
| 2674 | return parsed |
| 2675 | except ValueError: |
| 2676 | raise exceptions.ValidationError( |
| 2677 | self.error_messages["invalid_time"], |
| 2678 | code="invalid_time", |
| 2679 | params={"value": value}, |
| 2680 | ) |
| 2681 | |
| 2682 | raise exceptions.ValidationError( |
| 2683 | self.error_messages["invalid"], |
| 2684 | code="invalid", |
| 2685 | params={"value": value}, |
| 2686 | ) |
| 2687 | |
| 2688 | def pre_save(self, model_instance, add): |
| 2689 | if self.auto_now or (self.auto_now_add and add): |
no test coverage detected