I want to show the user the latest users that have seen his profile.
So everytime a logged user views another user's profile a ProfieView
object is stored in the database (or the date is updated if the user
that is viewing the profile has already viewed it before). I know this
can make the database grow too much, so I think I can run a cron
script daily that deletes all profile views older than a week (see
clear_old method). I don't know if the code is 100% correct, but is
the concept ok? Does it make sense to add a new object to the database
everytime another user views a profile?


class ProfileViews(models.Model):
    user = models.ForeignKey(User,related_name='latest_profile_views')
    viewer = models.ForeignKey(User)
    date = models.DateTimeField()

    def clear_old(self):
        d = datetime.now()-timedelta(weeks=1)
        p = ProfileViews.objects.filter(date__lte=d)
        p.delete()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to