1π
β
It means that there are two Post
s with as slug mypage
. Note that you do not filter on the author of your Post
, so if two authorβs have a mypage
, then this will raise an error.
You can filter on the author slug with:
class PostUpdateView(LoginRequiredMixin, UpdateView):
model = Post
form_class = PostForm
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(
author__username=self.kwargs['author']
)
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
Source:stackexchange.com