Reload django object from database

前端 未结 4 844
囚心锁ツ
囚心锁ツ 2020-12-13 16:30

Is it possible to refresh the state of a django object from database? I mean behavior roughly equivalent to:

new_self = self.__class__.objects.get(pk=self.pk         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 17:28

    I've found it relatively easy to reload the object from the database like so:

    x = X.objects.get(id=x.id)
    

提交回复
热议问题