mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-11 12:19:41 +00:00
perf: 优化 Session 支持 duration 字段
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
@@ -233,6 +234,14 @@ class Session(OrgModelMixin):
|
||||
target_ip = instance.get_target_ip() if instance else ''
|
||||
return target_ip
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
date_end = self.date_end or timezone.now()
|
||||
delta = date_end - self.date_start
|
||||
# 去掉毫秒的显示
|
||||
delta = timedelta(seconds=int(delta.total_seconds()))
|
||||
return str(delta)
|
||||
|
||||
@classmethod
|
||||
def generate_fake(cls, count=100, is_finished=True):
|
||||
import random
|
||||
|
Reference in New Issue
Block a user