| 3 | |
| 4 | |
| 5 | class GenericObjectID(models.PositiveIntegerField): # type: ignore[type-arg] |
| 6 | def value_from_object(self, obj): # type: ignore[no-untyped-def] |
| 7 | """ |
| 8 | Override to return natural_key of the object instead of pk; used by our custom serializer |
| 9 | to support import/export of objects with natural keys |
| 10 | """ |
| 11 | return obj.content_object.natural_key()[0] |
| 12 | |
| 13 | def to_python(self, value): # type: ignore[no-untyped-def] |
| 14 | """ |
| 15 | Override to allow string values; used by our custom deserializer |
| 16 | to support import/export using natural keys |
| 17 | """ |
| 18 | if value is None: |
| 19 | return value |
| 20 | if isinstance(value, str): |
| 21 | return value |
| 22 | try: |
| 23 | return int(value) |
| 24 | except (TypeError, ValueError): |
| 25 | raise exceptions.ValidationError( |
| 26 | self.error_messages["invalid"], |
| 27 | code="invalid", |
| 28 | params={"value": value}, |
| 29 | ) |
no outgoing calls
no test coverage detected
searching dependent graphs…