Consider the following scenario:
Our Django database objects must rely on IDs that are provided by external service A (ESA
) - this is because we use this ID to pull the information about objects that aren't created yet from the external directly. ESA
might shut down soon, so we also pull information about the same objects from external service B (ESB
), and save them as a fallback.
Because these IDs are relied on heavily in views and URLs, the ideal scenario would be to use a @property:
@property
dynamic_id = ESA_id
And then, if ESA
shuts down, we can switch easily by changing dynamic_id
to ESB_id
. The problem with this though, is that properties cannot be used in queryset filters and various other scenarios, which is also a must in this case.
My current thought is to just save ESA_id, ESB_id, and dynamic_ID as regular fields separately and assign dynamic_ID = ESA_id
, and then, in case ESA
shuts down, simply go over the objects and do dynamic_ID = ESB_id
.
But I feel there must be a better way?