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))
x = NotificationSettings.filter(user = request.user)
notice_settings = Notification.objects.get(notice_type = x)
return render_to_response('notification/notification.html', {
'u': u,
'v':v,
'x':x,
'notice_settings':notice_settings,
},
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 advance!
from datetime import datetime
notification.last_checked = datetime.now()
notification.save()
put that in the view for your link, and make sure that notification contains your Notification object!
精彩评论