Hey,
I have a model Book which can be added to user's Favorites. So I defined 2 classes:
class Book(models.Model):
name = models.CharField(max_length = 40)
class UserFavorite(models.Model):
book = models.ForeignKey(Book)
user = models.ForeignKey(User)
Now I'd like to show on the main page popular books with an icon either "add to favorites" or "remove from favorites". Basically I pass array of popular books to a template and from the template I loop thru this array and should say "if book.is_in_favorites(request.user): ...", but this is not possible from template.