diff options
author | Prabhu Ramachandran | 2017-08-24 11:15:57 +0530 |
---|---|---|
committer | GitHub | 2017-08-24 11:15:57 +0530 |
commit | 9dedf409a1da3c801d82a6a77d3f48f66e25264e (patch) | |
tree | 86ef943c5dc9d9beb6204e0ba07cd10fe1e887b1 /yaksh/forms.py | |
parent | 13b087846f66f450ad1ed12fd534ae2b30cddbcf (diff) | |
parent | c277c1f742d8d984fc7ab066cd3ac513e83f0d89 (diff) | |
download | online_test-9dedf409a1da3c801d82a6a77d3f48f66e25264e.tar.gz online_test-9dedf409a1da3c801d82a6a77d3f48f66e25264e.tar.bz2 online_test-9dedf409a1da3c801d82a6a77d3f48f66e25264e.zip |
Merge pull request #300 from ankitjavalkar/validate-quiz-prerequisite
Validate quiz prerequisite field
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r-- | yaksh/forms.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 3459be9..2740497 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -181,9 +181,13 @@ class QuizForm(forms.ModelForm): user = kwargs.pop('user') course_id = kwargs.pop('course') super(QuizForm, self).__init__(*args, **kwargs) - self.fields['prerequisite'] = forms.ModelChoiceField( - queryset=Quiz.objects.filter(course__id=course_id, - is_trial=False)) + + prerequisite_list = Quiz.objects.filter( + course__id=course_id, + is_trial=False + ).exclude(id=self.instance.id) + + self.fields['prerequisite'] = forms.ModelChoiceField(prerequisite_list) self.fields['prerequisite'].required = False self.fields['course'] = forms.ModelChoiceField( queryset=Course.objects.filter(id=course_id), empty_label=None) @@ -240,6 +244,13 @@ class QuizForm(forms.ModelForm): </p> """) + def clean_prerequisite(self): + prereq = self.cleaned_data['prerequisite'] + if prereq and prereq.prerequisite: + if prereq.prerequisite.id == self.instance.id: + raise forms.ValidationError("Please set another prerequisite quiz") + return prereq + class Meta: model = Quiz exclude = ["is_trial"] |