[Answered ]-Django: Accessing OneToOneField in template

2👍

These two lines are suspect:

Professor.objects.get(name=professor).question = question_instance
Professor.objects.get(name=professor).save()

The second line will get the Professor from the database again, and it won’t have your question instance attached anymore when you save it. Try this instead:

prof = Professor.objects.get(name=professor)
prof.question = question_instance
prof.save()
👤Ben

Leave a comment