diff --git a/quiz/views.py b/quiz/views.py index bb4c380..8fac91d 100644 --- a/quiz/views.py +++ b/quiz/views.py @@ -111,10 +111,10 @@ class MCQuestionCreate(CreateView): form_class = MCQuestionForm template_name = "quiz/mcquestion_form.html" - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - kwargs["quiz"] = get_object_or_404(Quiz, id=self.kwargs["quiz_id"]) - return kwargs + # def get_form_kwargs(self): + # kwargs = super().get_form_kwargs() + # kwargs["quiz"] = get_object_or_404(Quiz, id=self.kwargs["quiz_id"]) + # return kwargs def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -134,10 +134,20 @@ class MCQuestionCreate(CreateView): formset = context["formset"] if formset.is_valid(): with transaction.atomic(): - form.instance.quiz = get_object_or_404(Quiz, id=self.kwargs["quiz_id"]) - self.object = form.save() + # Save the MCQuestion instance without committing to the database yet + self.object = form.save(commit=False) + self.object.save() + + # Retrieve the Quiz instance + quiz = get_object_or_404(Quiz, id=self.kwargs["quiz_id"]) + + # set the many-to-many relationship + self.object.quiz.add(quiz) + + # Save the formset (choices for the question) formset.instance = self.object formset.save() + if "another" in self.request.POST: return redirect( "mc_create", diff --git a/templates/core/index.html b/templates/core/index.html index f6a5f45..045c546 100644 --- a/templates/core/index.html +++ b/templates/core/index.html @@ -49,9 +49,9 @@
{% endif %} diff --git a/templates/course/course_single.html b/templates/course/course_single.html index 27ff2c9..d261250 100644 --- a/templates/course/course_single.html +++ b/templates/course/course_single.html @@ -107,7 +107,7 @@ {% trans 'No video Uploaded.' %} {% if request.user.is_superuser or request.user.is_lecturer %} - + {% trans 'Upload now.' %} @@ -184,7 +184,7 @@ {% trans 'No File Uploaded.' %} {% if request.user.is_superuser or request.user.is_lecturer %} - + {% trans 'Upload now.' %} diff --git a/templates/course/program_single.html b/templates/course/program_single.html index c1ae053..c04e9f8 100644 --- a/templates/course/program_single.html +++ b/templates/course/program_single.html @@ -95,7 +95,7 @@ {% trans 'No course for this progrm.' %} {% if request.user.is_superuser %} - + {% trans 'Add one now.' %} diff --git a/templates/quiz/mcquestion_form.html b/templates/quiz/mcquestion_form.html index a4808f2..8489716 100644 --- a/templates/quiz/mcquestion_form.html +++ b/templates/quiz/mcquestion_form.html @@ -52,7 +52,7 @@CRUD (Create, Retrieve, Update & Delete) lecturers
CRUD (Create, Retrieve, Update & Delete) {% trans 'students' %}
CRUD (Create, Retrieve, Update & Delete) {% trans 'sessions' %}
→ Others
+→ Others