提问人:user11225404 提问时间:10/5/2023 更新时间:10/5/2023 访问量:49
Django-table 错误输出
Django-table wrong output
问:
我有 django 模型:
class Sessions(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey('Users', on_delete=models.CASCADE, related_name='user')
session_start = models.DateTimeField()
last_confirmation = models.DateTimeField(null=True)
error_status = models.CharField(max_length=50, default="Lost connection.", null=True)
session_end = models.DateTimeField(null=True)
status = models.CharField(null=True, max_length=1)
我有一个视图函数,它必须返回带有三列('session_start','last_confirmation',differenc_time ('last_confirmation' - 'session_start')的 QuerySet:
def user_home(request):
info = Sessions.objects.filter(user=request.user.id).annotate(
time_difference=ExpressionWrapper(
F('last_confirmation') - F('session_start'),
output_field=fields.DurationField()
)
).values('last_confirmation', 'session_start', 'time_difference')
return render(request, 'home_user.html',
context={'data': info})
答: 暂无答案
评论