Моя проблема заключается в том, что когда я пытаюсь отобразить информацию профиля определенного пользователя, я получаю отображаемую информацию несколько раз в соответствии с количеством созданных сообщений определенным пользователем.Я не знаю, как изменить свой запрос, чтобы получить информацию о профиле пользователя один раз, когда я нажму на его имя.
Я создал метод get_context_data, но я не знаю, как изменить запрос, чтобы получить информацию о пользователе.
views.py
class ProfilPostView(ListView):
model=Post
template_name='profile.html'
#display posts created by user
def get_queryset(self):
return Post.objects.filter(author__username=self.kwargs['slug']).order_by('created_on')
#return Post.objects.filter(author=self.request.user).order_by('created_on')
#display profile information of user
def get_context_data(self,**kwargs):
context=super(ProfilPostView,self).get_context_data(**kwargs)
context['profiles']=Post.objects.filter(author__username=self.kwargs['slug'])
return context
profile.html
<h3 style="padding-left:40%" class="lead">Name: {{ profiles.first_name}} {{profiles.last_name}}</h3>
<p class="text-muted" style="padding-left:40%">Created: {{profiles.created_time.day}}.{{profiles.created_time.month}}.{{profiles.created_time.year}}</p>
<p class="text-muted" style="padding-left:40% ">Email: {{profiles.email}}</p>
**UPDATE**
the code that displays the profile informations multiple times is the below one. the upper code is the one i changed for get_context_data method
{% for post in object_list%}
<h3 style="padding-left:40%" class="lead">Name: {{ post.author.first_name}} {{post.author.last_name}}</h3>
<p class="text-muted" style="padding-left:40%">Created: {{post.author.created_time.day}}.{{post.author.created_time.month}}.{{post.author.created_time.year}}</p>
<p class="text-muted" style="padding-left:40% ">Email: {{post.author.email}}</p>
{% endfor %}