I am using Django 3.2.
I have a model like this:
class MyModel(models.Model):
last_valid_field_values = models.TextField(help_text='JSON field of fieldnames and values')
# ...
I want to be able to monkey patch my queries, so that when fetching MyModel instances, I can added an attribute last_values_dict — which is just the loaded JSON of the last_valid_field_values.
So I would have something like this (pseudocode):
def callback_func(instance):
instance.last_values_dict = json.loads(instance.last_valid_field_values)
MyModel.objects.all().apply_some_function_to_monkey_patch(callback_func)
How can I do this? I also think that possibly, this could be done via a generator iterating over the QuerySet?