我有一个DetailView,其中包含一个get函数。此get函数检查某个条件是否成立,如果满足,则抛出错误。但是,我在查询post=
的查询中获取子弹ID时遇到困难,如何在此处添加子弹ID?
class ReportPostView(LoginRequiredMixin, DetailView):
login_url = '/login/'
template_name = 'core/report-post.html'
model = Post
slug_field = 'id'
def get(self, request, *args, **kwargs):
if Report.objects.filter(actor=self.request.user, post={{ slug_id_should_be_here }}).exists():
return HttpResponseNotFound("You have already reported this Post")
else:
return
答案 0 :(得分:1)
您可以从{warfs}中获得子弹:kwargs['id']
。