Django:如何在基于类的视图中获取昨天的查询集?
http://ccbv.co.uk/projects/Django/1.4/django.views.generic.dates/TodayArchiveView/
我使用 TodayArchiveView。
顺便说一句,如果 TodayArchiveView 得到 None,TodayArchiveView.as_view() 会引发 Http404。
在这种情况下,我想在当前模型(表)中推送昨天的数据......
我应该怎么办?
一些代码在这里:
网址.py
from django.conf.urls import patterns, include, url
from crm.views import *
urlpatterns = patterns('',
(r'^workDailyRecord/$', workDailyRecord),
)
视图.py
from django.views.generic import TodayArchiveView
from django.http import Http404
from crm.models import *
def workDailyRecord(request):
if request.method === 'GET':
tView.as_view() # I want call class-based generic views at this line.
elif:
try:
return tView.as_view()(request)
except Http404:
# I want to push data at yesterday in 'WorkDailyRecord' model
pass
class tView(TodayArchiveView):
model = WorkDailyRecord
context_object_name = 'workDailyRecord'
date_field = 'date'
template_name = "workDailyRecord.html"
模型.py
from django.db import models
class WorkDailyRecord(models.Model):
date = models.DateTimeField(auto_now_add=True)
contents = models.TextField()