django url user id versus userprofile id problem

Posted by dana on Stack Overflow See other posts from Stack Overflow or by dana
Published on 2010-06-07T10:02:28Z Indexed on 2010/06/07 10:32 UTC
Read the original article Hit count: 365

Filed under:
|
|
|

hello there, i have a mini comunity where each user can search and find another user 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 wil 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 urls (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 %}

thanks in advance!

© Stack Overflow or respective owner

Related posts about django

Related posts about user