django: Selecting questions that was not asked
- by Oleg Tarasenko
Hi,
I am creating small django application which holds some few questions (and answers for them)
What I want to do is to show user random question, but only from those which was not solved by him yet. I wonder how to do this.
For now, I defined user profile model this way:
class UserProfile(models.Model):
rank = models.IntegerField(default = 1)
solvedQ = models.ManyToManyField(Question)
user = models.ForeignKey(User, unique=True)
So solved problems are added this way:
if user.is_authenticated():
profile = user.get_profile()
profile.rank += 1
profile.solvedQ.add(Question.objects.get(id=id))
Now if the view must show random question, but not from already solved list...
Is there a good way to intersect Questions and solvedQuestions.... so question is chosen from the unsolved list?