Reputation: 3029
I receive this error: Caught AttributeError while rendering: 'dict' object has no attribute 'friendship'. The problem is when i try to get the value of friend.friend in the custom template tag. The module 'friends_for_user' is right. I have:
models
class FriendshipManager(models.Manager):
def friends_for_user(self, user):
friends = []
for friendship in self.filter(from_user=user).select_related(depth=1):
friends.append({"friend": friendship.to_user, "friendship": friendship})
for friendship in self.filter(to_user=user).select_related(depth=1):
friends.append({"friend": friendship.from_user, "friendship": friendship})
return friends
template tags
def render(self, context):
user = self.user.resolve(context)
num = self.num.resolve(context)
my_friends = Friendship.objects.friends_for_user(user)
potential_friends = []
for friend in my_friends:
potential_friends.append(Friendship.objects.friends_for_user(friend.friend)) //This line is the error.
context[self.context_name] = potential_friends
return ''
Upvotes: 3
Views: 3575
Reputation: 143
It looks like you're using a dictionary not an object. Try potential_friends.append(Friendship.objects.friends_for_user(friend['friend']))
Upvotes: 7