Django model中的save后的return

时间:2023-03-08 17:29:58

先给结论吧:在Django model的操作函数中,obj.save()后再执行return obj会返回obj的ID

看例子:

...
def create_session(self,bind_host_obj,random_tag):
session_obj = models.SessionRecord(
user = self.user,
bind_host = bind_host_obj,
rand_tag = random_tag
)
session_obj.save()
return session_obj

相关文章