models.py 847 B

1234567891011121314151617181920212223
  1. from datetime import timedelta
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils import timezone
  5. class ThreadRecord(models.Model):
  6. user = models.ForeignKey('users.User')
  7. forum = models.ForeignKey('forums.Forum')
  8. thread = models.ForeignKey('threads.Thread')
  9. updated = models.DateTimeField()
  10. class ForumRecord(models.Model):
  11. user = models.ForeignKey('users.User')
  12. forum = models.ForeignKey('forums.Forum')
  13. updated = models.DateTimeField()
  14. cleared = models.DateTimeField()
  15. def get_threads(self):
  16. threads = {}
  17. for thread in ThreadRecord.objects.filter(user=self.user, forum=self.forum, updated__gte=(timezone.now() - timedelta(days=settings.READS_TRACKER_LENGTH))):
  18. threads[thread.thread_id] = thread
  19. return threads