先给结论吧:在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