1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個贊
您可以過濾查詢集,使其僅包含Post最近 24 小時內(nèi)撰寫的帖子:
from datetime import timedelta
from django.utils.timezone import now
class PostUpdateView(LoginRequiredMixin,SuccessMessageMixin,UpdateView):
model = Post
form_class = PostForm
success_message = "updated successfully"
template_name = 'store/create.html'
success_url = reverse_lazy('lists')
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(
date__gte=now() - timedelta(days=1)
)
def form_valid(self,form):
return super().form_valid(form)
如果更新周期已“過期”,這將返回 HTTP 404 響應(yīng)。
添加回答
舉報