for fr, to in list(d.items()):
    Test.objects.filter(id=fr).update(id=to)
test_obj = Test.objects.get(id=to)
Question.objects.filter(test_id=fr).update(test=test_obj)
Django update on queryset to change ID of ForeignKey