简体   繁体   English

使用Django后处理考勤数据

[英]Post processing attendance data with Django

I have a web app which tries to determine when people are attending events. 我有一个网络应用程序,它试图确定人们何时参加活动。

class Attendee(models.Model):
    location = models.ForeignKey(Location)
    user = models.ForeignKey(User)
    checked_in = models.DateTimeField()
    checked_out = models.DateTimeField()
    last_active = models.DateTimeField()

An Attendee is checked in whenever they sign in to a particular location, and an attendee is checked out whenever they sign out. 每当他们登录到特定位置时,签到者就会签到,而每当他们退出时,签出者都会签出。

The problem is that determining when somebody is actually "checked out", because they may not actively sign out of the Django user system, I have to find a way to register them as being checked out after 24 hours. 问题在于,确定某人实际上何时“退房”,因为他们可能没有主动退出Django用户系统,所以我必须找到一种方法将其注册为24小时后退房的人。

At the moment I am using a horribly simplistic ORM query in a manager to list "active" and "inactive" users on the site. 目前,我正在管理器中使用极其简单的ORM查询,以列出站点上的“活动”和“非活动”用户。

expires = datetime.datetime.today() - datetime.timedelta(seconds=settings.AUTO_CHECKOUT_AFTER)
# Get people who were last active more than 24 hours ago OR who have checked out
inactive_users = User.objects.all().filter(Q(attendee__last_active__lt = expires) \
                 | Q(attendee__checked_out__lte = datetime.datetime.now()), \
                 attendee__location=location).exclude(attendee__checked_out = None, attendee__checked_in__gte = expires).distinct()

What is the better way to do this? 什么是更好的方法呢? I'm guessing need a Django equivalent to a CRON job to automatically check-out users that are inactive. 我猜想需要一个相当于CRON作业的Django,以自动检出不活动的用户。

You don't need a 'Django equivalent to a cron job', you just need a cron job. 您不需要“相当于cron作业的Django”,而只需要cron作业。

The cron should run a standalone Django script - you can do this in several different ways, but the easiest way is to create a standalone ./manage.py command . cron应该运行一个独立的Django脚本-您可以通过几种不同的方式执行此操作,但是最简单的方法是创建一个独立的./manage.py命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM