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.
At the moment I am using a horribly simplistic ORM query in a manager to list "active" and "inactive" users on the site.
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.
You don't need a 'Django equivalent to a cron job', you just need a cron job.
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.
精彩评论