1👍
✅
You can use a SerializerMethodField
my_h = serializers.SerializerMethodField()
def get_my_h(self, obj):
return obj.b.c.d.e.f.g.h or some_better_logic_here_to_actually_get_h
The actual logic above you’ll need to tweak to suit your needs (and I wouldn’t expect it to perform well due to the level you’re trying to reach)… but essentially obj
is the current instance you’re serializing so you can work with it as you wish
Source:stackexchange.com