값을 갱신하는 테스트를 작성할 때 유용한 기능이다
obj = MyModel.objects.create(val=1) MyModel.objects.filter(pk=obj.pk).update(val=F('val') + 1) # At this point obj.val is still 1, but the value in the database # was updated to 2. The object's updated value needs to be reloaded # from the database. obj.refresh_from_db() self.assertEqual(obj.val, 2)
참고: https://django-orm-cookbook-ko.readthedocs.io/en/latest/refresh_from_db.html
https://docs.djangoproject.com/en/3.1/ref/models/instances/