I have two models:
Model Student:
name = models.CharField()
..... ....
wishlist = models.ManyToManyField(University, blank=True)
Model University:
name = models.CharField()
...... . .. . . . .
Basically am just creating a wishlist by which user can like on a university and then add it to their wishlist ! ( am expressing this via a heart icon ), So when user reclicks on same item then it will remove it from the wishlist, thats it !
The problem is that, how to check if a user has liked particular university ?
here is my code:
def index(request):
univesity = University.objects.filter(is_approved=True)
context = {'univesity': univesity}
return render(request, 'search/index.html', context)
above is where i fetch all university for searching purpose ! In this i need to check if the use have already added the university to the wishlist relationship. And if its true then the heart icon will turn into red else empty color !
And now this is how i show on template
{% if data.student_set.all %}
<button><em class="icon ni ni-heart-fill" ></em></button>
{% else %}
<button><em class="icon ni ni-heart"></em></button>
{% endif %}
It doesnt work the way i expected ! please guide