Add exclude so the current user doesn't see their name
This commit is contained in:
parent
1d688a4123
commit
1de7ad09ec
@ -13,6 +13,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from accounts.models import User
|
||||
from .models import Topic, Post, Comment
|
||||
from .forms import PostForm, PostCreateForm, CommentCreateForm
|
||||
|
||||
@ -127,6 +128,15 @@ class PostDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Post
|
||||
pk_url_kwarg = 'post_pk'
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Post.objects.all().prefetch_related(
|
||||
models.Prefetch(
|
||||
'recipients',
|
||||
queryset=User.objects.exclude(pk=self.request.user.pk)
|
||||
)
|
||||
)
|
||||
return queryset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
object_content_type = ContentType.objects.get_for_model(self.object).pk
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user