diff options
author | mahesh | 2017-08-24 23:26:46 +0530 |
---|---|---|
committer | mahesh | 2017-08-24 23:26:46 +0530 |
commit | 751dc83729e5bf57b2dd1a2798bb7b527a2e3584 (patch) | |
tree | fa1d11bd00ac9060cfa36056f62d1321455a4916 /yaksh/forms.py | |
parent | 6ab383c02085936ecc20ffeb4b9f41ca642256c3 (diff) | |
parent | 9d5c4a01fd7856f1ef8793b75a9734324c254344 (diff) | |
download | online_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.tar.gz online_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.tar.bz2 online_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.zip |
Merge branch 'master' of https://github.com/fossee/online_test into yaml_questions
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"] |