2👍
✅
Couple options depending on how much refactoring you’re willing to do.
- First up if you are (or can easily upgrade) to Postgres, then current versions of django directly support using a json field from there you can convert your queries to
defer()
that field if needed. - Next option, convert
instance_data
to_instance_data
and makeinstance_data
a@cached_property
using django.utils. That will allow you to load it once when you access it from the instance and will cache it automatically for future uses.
Last thing I want to note, be careful with your _post_init()
because if it’s blindly setting values from your json it could easily shadow values that you might want (e.g. what if your json has a field called save
in it?)
👤Paul
Source:stackexchange.com