On Dec 13, 2007 8:59 AM, Roboto <[EMAIL PROTECTED]> wrote:
>
> How do forums ie PHPBB and gmail know if I've viewed a topic or not?
>
> I can think of only 2 methods - 1 is session, and the second is
> database. However, if I change computers and therefore changing my
> session it's still able to ensure track what I've viewed. It
> therefore leads me to believe that they are tracking via database
>
> If that is the case? What would be the logic to set this up??
I would imagine there's something stored in a database to track when
you last read a topic/mail, yes :)
Here's a pared-down snippet of how I do it in my forum application [1]
by way of example:
# models.py
class TopicTracker(models.Model):
"""
Tracks the last time a User read a particular Topic.
"""
user = models.ForeignKey(User, related_name='topic_trackers')
topic = models.ForeignKey(Topic, related_name='trackers')
last_read = models.DateTimeField()
def update_last_read(self, last_read):
"""
Updates this TopicTracker's ``last_read``.
"""
self.last_read = last_read
model_utils.update(self, 'last_read')
update_last_read.alters_data = True
# views.py
def topic_detail(request, topic_id):
topic = get_object_or_404(Topic, pk=topic_id)
if request.user.is_authenticated():
last_read = datetime.datetime.now()
tracker, created = \
TopicTracker.objects.get_or_create(user=request.user, topic=topic,
defaults={'last_read':
last_read})
if not created:
tracker.update_last_read(last_read)
transaction.commit()
# ...
Regards,
Jonathan.
[1] http://www.jonathanbuchanan.plus.com/repos/forum/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---