I have a small problem and wondering if someone can help me out. I’m trying to do a check to see if the request.user is one of the user’s in the ManyToMany relationship table. Is there a way to accomplish this?
Example:
I want to check if the user is following the business page, and if they are, give them the ability to unfollow it and vice versa.
I have:
followers = models.ManyToManyField(User, related_name="Followers", null=True, blank=True)
Just wondering if theres a way to check the request.user.id against the followers table for that specific id.
Thanks everyone.
Steve
This “djangoic” way to do it:
The more “pythonic” way, which is not recommended because it is very inefficient db wise:
(This later one loads all users data into python, while the first one uses a db query)