Posted By

Vs3K on 09/09/09


Tagged

python users django


Versions (?)

Django: Who Online (modules.py)


 / Published in: Python
 

  1. class UsersOnline(models.Model):
  2. # Showing users online
  3. username = models.CharField(max_length=100)
  4. time = models.DateTimeField()
  5. url = models.URLField()
  6.  
  7. def __unicode__(self):
  8. return self.username
  9.  
  10. def recountUsersOnline():
  11. users = UsersOnline.objects.all()
  12. date_now = datetime.now()
  13. # Deleting expired users
  14. for user in users:
  15. dt = date_now - user.time
  16. if (dt.seconds > 300):
  17. # User expired
  18. user.delete()
  19.  
  20. def addUserOnline(username, url):
  21. try:
  22. user = UsersOnline.objects.get(username=username)
  23. user.time = datetime.now()
  24. except:
  25. user = UsersOnline(username=username, time=datetime.now(), url=url)
  26. user.save()

Report this snippet  

You need to login to post a comment.