I have user profile like
class UserProfile(models.Model):
completed_tasks = models.ManyToManyField(Tasks)
then task model
class Tasks(models.Model):
<...fields...>
Then I want to filter some开发者_StackOverflow中文版 task and have a queryset property "completed" that marks if task objects is in user completed_tasks.
Example
t = Tasks.objects.filter(...).order_by(...)
t[0].completed # False
t[1].completed # True
Any ideas how can I do that?
Tricky question: in your model task completion depends on user having it in his collection, which makes the logic ambiguous. Is the task completed if any user completed it? Maybe all users need to complete it? Or maybe answer depends on user asking? Try making your models more defined.
精彩评论