def METHOD_NAME(Model, field, value):
    if type(getattr(Model, field)) in [
        ForwardManyToOneDescriptor,
        ForwardOneToOneDescriptor,
    ]:
        other_model = getattr(Model, field).get_queryset().model
        # in case is a dictionary, we have to retrieve the object with every key
        if isinstance(value, dict):
            real_vals = {}
            for key, real_val in value.items():
                real_vals[key] = METHOD_NAME(other_model, key, real_val)
            value = other_model.objects.get_or_create(**real_vals)[0]
        # it is just the primary key serialized
        else:
            value = other_model.objects.get(pk=value)
    return value