search through related field for specific related object
- by dotty
Hay, I'm working on a simple voting system, where users can vote on a poll.
My model looks like this
class Poll(models.Model):
question = models.CharField()
votes = models.IntegerField()
usersVoted = models.ManyToManyField(User)
Now, i want to scan through the usersVoted field to see if a User object is in there. This User object will then be matched against a logged in User (User obj saved in a session).
If the User has voted i want to be able to set a 'has_voted' field. I then want to use this field in my view.
I will be using the Property() thingy inside the model to work this 'has_voted' value out.
Like so
def _can_vote(self):
return False
can_vote = property(_can_vote)
Obviously it'll return a Bool.
Any ideas how to search through a related field to find a specific Object?