I have the following models
class Book(models.Model):
name = models.CharField(max_length=140)
class UserProfile(models.Model):
favorites = models.ManyToManyField(Book, null=True, blank=True)
user = models.OneToOneField(User)
I need to craete a list of all books and show which ones are favorites and which ones are not.
I need a queryset for a view that gets me all the books like
Book.objects.all()
but i also need to know for each book if it is a favorite for that user and then pass this queryset to the template.
Thanks.
This is a relatively straightforward use of the ManyToManyField.
ETA: Since you say you want to add it to the template, give it to the template as a list of tuples.
In your template, have the code