Skip to content

Commit

Permalink
Fix: quiz admin form #2
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Oct 6, 2024
1 parent 5d80d41 commit 36b18b2
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions quiz/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ class ChoiceInline(admin.TabularInline):


class QuizAdminForm(TranslationModelForm):
class Meta:
model = Quiz
exclude = []

questions = forms.ModelMultipleChoiceField(
queryset=Question.objects.all().select_subclasses(),
required=False,
label=_("Questions"),
widget=FilteredSelectMultiple(verbose_name=_("Questions"), is_stacked=False),
)

class Meta:
model = Quiz
fields = ["title_en"]

def __init__(self, *args, **kwargs):
super(QuizAdminForm, self).__init__(*args, **kwargs)
if self.instance.pk:
self.fields[
"questions"
].initial = self.instance.question_set.all().select_subclasses()
self.fields["questions"].initial = (
self.instance.question_set.all().select_subclasses()
)

def save(self, commit=True):
quiz = super(QuizAdminForm, self).save(commit=False)
Expand All @@ -48,20 +48,26 @@ def save(self, commit=True):


class QuizAdmin(TranslationAdmin):
form = QuizAdminForm
fields = ('title', 'description',)
list_display = ("title",)
# list_filter = ('category',)
search_fields = (
"description",
"category",
)
pass
# form = QuizAdminForm
# fields = (
# "title",
# "description",
# )
# list_display = ("title",)
# # list_filter = ('category',)
# search_fields = (
# "description",
# "category",
# )


class MCQuestionAdmin(TranslationAdmin):
list_display = ("content",)
# list_filter = ('category',)
fieldsets = [(u'figure' 'quiz' 'choice_order', {'fields': ("content","explanation")})]
fieldsets = [
("figure" "quiz" "choice_order", {"fields": ("content", "explanation")})
]

search_fields = ("content", "explanation")
filter_horizontal = ("quiz",)
Expand Down

0 comments on commit 36b18b2

Please sign in to comment.