[Answered ]-Use variable as key name for model

1👍

You can use Python gettattr

@classmethod
def get_my_msg(cls,key):
    res = cls.objects.latest("updated_at")
    return getattr(res, key)

Leave a comment