Django:如何在基于类的视图中设置yester查询?
http://ccbv.co.uk/projects/Django/1.4/django.views.generic.dates/TodayArchiveView/
我使用TodayArchiveView。
顺便说一句,如果TodayArchiveView获得None,则TodayArchiveView.as_view()会提升Http404。
在这种情况下,我想在昨天的当前模型(表格)中推送数据......
我该怎么办?
这里的一些代码:
urls.py
from django.conf.urls import patterns, include, url
from crm.views import *
urlpatterns = patterns('',
(r'^workDailyRecord/$', workDailyRecord),
)
views.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"
models.py
from django.db import models
class WorkDailyRecord(models.Model):
date = models.DateTimeField(auto_now_add=True)
contents = models.TextField()