Django notification get date one accesses a link
Posted
by dana
on Stack Overflow
See other posts from Stack Overflow
or by dana
Published on 2010-06-12T10:59:48Z
Indexed on
2010/06/12
11:02 UTC
Read the original article
Hit count: 283
hi there, i'm making a notification system, so that a user in a virtual community to be announced when someone sends him a message, or starts following him (the follow relation is like a friend relation, but it is not necessarily reciprocal)
my view function:
def notification_view(request, last_checked):
u = Relation.objects.filter(date_follow>Notification.objects.get(last_checked=last_checked))
v = Message.objects.filter(date>Notification.objects.get(last_checked=last_checked))
if u:
notification_type = follow
if notice_settings == receive_notification or notice_settings == only_follow
following = u
if v:
notification_type = message
if notice_settings == receive_notification or notice_settings == only_messages
message = v
return render_to_response('notification/notification.html', {
'following': following,
'message':message,
},
context_instance=RequestContext(request))
the models.py:
class NoticeType(models.Model):
follow = models.ForeignKey(Relations, editable = False)
message = models.ForeignKey(Messages)
classroom_invitation = models.ForeignKey(Classroom)
class Notification(models.Model):
receiver = models.ForeignKey(User, editable=False)
date = models.DateTimeField(auto_now=True, editable = False)
notice_type = models.ForeignKey(NoticeType, editable = False, related_name = "notification_type")
sent = models.BooleanField(default = True)
last_checked = models.DateTimeField(auto_now=True, editable = False)
class NotificationSettings(models.Model):
user = models.ForeignKey(User)
receive_notifications = models.BooleanField(default = True)
only_follow = models.BooleanField(default = False)
only_message = models.BooleanField(default = False)
only_classroom = models.BooleanField(default = False)
#receive_on_email = models.BooleanField(default = False)
my problem is:
i want last_checked to be the time when someone acceses a link (the notification link). How can i possibily save that time? how can i get it?
thanks in avance!
© Stack Overflow or respective owner