In your Topic
model you're allowing for more than one element to have the same topic
field. You have created two with the same one already.
topic=models.TextField(verbose_name='Thema')
Now when trying to add a new learningObjective
you seem to want to add it to only one Topic
that matches what you're sending on the form. Since there's more than one with the same topic
field get
is finding 2, hence the exception.
You can either add the learningObjective
to all Topics with that topic
field:
for t in topic.objects.filter(topic=request.POST['Thema']):
t.learningObjectivesTopic.add(neuesLernziel)
or restrict the Topic
model to have a unique topic
field and keep using get
, but that might not be what you want.