MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / GenericObjectID

Class GenericObjectID

api/metadata/fields.py:5–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class 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 )

Callers 2

MetadataClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…