In your template people_list is list of UserProfile instances so
avatar is accessed by {{people.avatar}}
If you try to iterate through friends that you can access to avatar
like so:
{{friend.get_profile.avatar}}
Of course if you set proper AUTH_PROFILE_MODULE setting.

On 19 янв, 22:24, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm using the built in authentication of Django, so new users who
> register go through the User model. I also have a custom UserProfile
> model that links directly to the User model via a ForeignKey.
>
> This is my completed UserProfile model:
>
> ########################
> # File: people/models.py
> ########################
> class UserProfile(models.Model):
>         user = models.ForeignKey(User, unique=True)
>         gender = models.CharField(maxlength=100, choices=GENDER_CHOICES,
> blank=True)
>         birthday = models.DateField(blank=True)
>         living = models.ForeignKey(Locations, blank=True)
>         friends = models.ManyToManyField(User, blank=True,
> related_name='friend_set')
>         avatar = models.ImageField(upload_to='photos/', blank=True,
> null=True)
> ########################
>
> The part I am having a slight problem with is the friends field. As
> you can see it has a ManyToMany relationship with User, which is fine.
> I can add add friends without any problems, but when it comes to
> accessing the list of friends I'm having some problems seeing the
> Avatar and Gender, which live within UserProfile.
>
> This is how I am pulling out the data:
>
> ########################
> # File: people/views.py
> ########################
> def people_friends(request,u):
>         user = UserProfile.objects.get(user=u)
>         friends = user.friends.all()
>
>         # Use the object list view for the heavy lifting
>         return list_detail.object_list(
>                 request,
>                 queryset = friends,
>                 template_name = "people/people_by_user.html",
>                 template_object_name = "people"
>         )
> ########################
>
> And then in my template file I am printing them like this:
>
> ########################
> # File: templates/people/people_by_user.html
> ########################
> {% for people in people_list %}
> {{ people.username }}
> {{ people.avatar }}
> {% endfor %}
> ########################
>
> As mentioned above, the problem is people.avatar doesn't print
> anything. I tried people.userprofile.avatar but again, nothing
> happens...
>
> Any ideas? Do I need to setup a ManyToMany with an intermediary table
> or something?
>
> Cheers,
> Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to