I have a mini comunity where each user can search and find another user's profile. Userprofile is a class model, indexed differently compared to user model class (user id is not equal to userprofile id).
But I cannot see a user profile by typing in the URL the corresponding id. I only see the profile of the currently logged in user.
Why is that? I'd also want to have in my URL the username (a primary key of the user table also) and NOT the id (a number).
The guilty part of the code is:
What can I replace that request.user with so that it will actually display the user I searched for, and not the currently logged in?
def profile_view(request, id):
u = UserProfile.objects.get(pk=id)
cv = UserProfile.objects.filter(created_by = request.user)
blog = New.objects.filter(created_by = request.user)
return render_to_response('profile/publicProfile.html',
{
'u':u,
'cv':cv,
'blog':blog,
},
context_instance=RequestContext(request))
In file urls.py (of the accounts app):
url(r'^profile_view/(?P<id>\d+)/$',
profile_view,
name='profile_view'),
And in template:
<h3>Recent Entries:</h3>
{% load pagination_tags %}
{% autopaginate list 10 %}
{% paginate %}
{% for object in list %}
<li>{{ object.post }} <br />
Voted: {{ vote.count }} times.<br />
{% for reply in object.reply_set.all %}
{{ reply.reply }} <br />
{% endfor %}
<a href=''> {{ object.created_by }}</a> <br />
{{object.date}} <br />
<a href = "/vote/save_vote/{{object.id}}/">Vote this</a>
<a href="/replies/save_reply/{{object.id}}/">Comment</a> </li>
{% endfor %}