i am trying to add an updateView using class based view to my blog_post whenever i hop in to any post-detail and to the update url like is http://127.0.0.1:8000/pages/blog/15/update/ i get a 403 Forbidden error in which i only want each user to update their blogpost which they wont be able to update other user blogpost so but so i decided to use UserPassesTestMixin which would require tesc_func but my tesc_func is not applying what i asked for tho i am using CustomUser model so i dont know if that will change the way i will write in my tesc_func here is my code,
views.py
class BlogUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Blog
fields = ['title', 'categories', 'overview', 'thumbnail', 'summary']
def form_valid(self, form):
form.instance.user = Doctor.objects.get(user=self.request.user)
return super().form_valid(form)
def test_func(self):
blog = self.get_object()
if self.request.user == blog.user:
return True
return False
urls.py
path('blog/<int:pk>/update/', BlogUpdateView.as_view(), name='blog-update'),