I have a table called Tip and table called FavoritedTips. Users favorite Tips in my app and the tip ID and user ID are added to the favoritedTips table.
class FavoritedTip(models.Model):
tip = models.ForeignKey(Tip)
user = models.ForeignKey(User)
I now need to put a star next to the tip when the tips appear in the list. But of course tips = Tip.objects.filter(list=list) doesn’t have a tip.favoritedtip column.
What’s the easiest thing to do in my template to know which tip has been favorited?
I presume you want to display a list of tips and for each one you need to know if this is a favorite of the current user.
You can do it with a custom
templatetagif you really want to do that at the template level, but you’d better build your data structure in the view :And then in your template :