我有一个页面,用户可以在其中报告帖子。如果他们已经报告了该特定帖子,则不允许他们访问此页面。我正在使用DetailView
,帖子ID为子弹,因此看起来像这样:/report/p/3/
这是我到目前为止的内容:
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, but I don't know how to get it from the slug }}).exists():
return HttpResponseNotFound("You have already reported this Post")
else:
return
如何检查这种情况并重定向用户?