2010-06-12 17 views
0

我正在製作一個通知系統,以便當有人向他發送消息或者開始追隨他時,虛擬社區中的用戶將被宣佈(後面的關係就像是一個朋友關係,但它不一定是倒數)Django通知獲取日期一訪問鏈接

我查看功能:

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)) 

的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) 

我的問題是:

我想last_checked是有人加入鏈接(通知鏈接)的時間。我如何可能節省時間?我怎麼才能得到它?

在此先感謝!

回答

1
from datetime import datetime 

notification.last_checked = datetime.now() 
notification.save() 

把它放在您的鏈接的視圖中,並確保通知包含您的通知對象!

+0

謝謝,它的工作原理! – dana 2010-06-12 13:30:10