@classmethod
    def to_python(cls, value, model_ref=None, pk=None):
        if model_ref is None:
            if value is None:
                return None

            if isinstance(value, models.Model):
                return value

            model_ref, pk = decode_pk(value)

        try:
            pk = int(pk)
        except (__HOLE__, TypeError):
            raise forms.ValidationError('Invalid instance key.')

        model = cls.load_model(model_ref)
        try:
            return model.objects.get(pk=pk)
        except model.DoesNotExist:
            raise forms.ValidationError('Invalid instance key.')
dataset/ETHPy150Open potatolondon/djangae/djangae/forms/fields.py/GenericRelationFormfield.to_python