문제

I am new to Django and need to create a form for team scheduling. The form reads the voter ID through a checkbox, and then add the object of voter ID to the particular Choice. Choice has a field named

voters = ManyToMany(Voter)

Now, what I do is:

v = Voter.objects.filter(voter_name__icontains=request.POST.get('voter'))
selected_choice.voter.add(v[0])

But this won't prevent them from voting twice. Does add() give an silenced error if the voter selected is already in the Choice?

Many Thanks

도움이 되었습니까?

해결책

You can add twice to ManyToMany. Look at the doc https://docs.djangoproject.com/en/1.6/topics/db/examples/many_to_many/#many-to-many-relationships, search for "Adding a second time is OK"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top