.
This commit is contained in:
+5
-4
@@ -25,7 +25,7 @@ from generic.models import Examination
|
||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||
from django.forms.widgets import RadioSelect, TextInput, Textarea
|
||||
|
||||
import select2.fields
|
||||
from dal import autocomplete
|
||||
|
||||
class AnatomyAnswerForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -90,9 +90,10 @@ class AnatomyQuestionForm(ModelForm):
|
||||
required=False,
|
||||
queryset=Structure.objects.all(),
|
||||
)
|
||||
#self.fields["structure"] =select2.fields.ChoiceField(
|
||||
#choices=Structure.objects.all(),
|
||||
#overlay="Choose an author...")
|
||||
self.fields["structure"] = ModelChoiceField(
|
||||
queryset=Structure.objects.all(),
|
||||
widget=autocomplete.ModelSelect2(url='anatomy:struture-autocomplete')
|
||||
)
|
||||
|
||||
self.fields["examination"] = ModelChoiceField(
|
||||
required=False,
|
||||
|
||||
@@ -147,4 +147,9 @@ urlpatterns = [
|
||||
views.GenericViews.user_answer_delete_multiple,
|
||||
name="user_answer_delete_multiple",
|
||||
),
|
||||
path(
|
||||
"structure-autocomplete",
|
||||
views.StructureAutocomplete.as_view(),
|
||||
name="structure-autocomplete",
|
||||
),
|
||||
]
|
||||
|
||||
@@ -24,6 +24,8 @@ from django.http import Http404, JsonResponse
|
||||
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
from dal import autocomplete
|
||||
|
||||
from .forms import (
|
||||
AnatomyAnswerForm,
|
||||
AnswerFormSet,
|
||||
@@ -998,3 +1000,16 @@ GenericViews = GenericViewBase("anatomy", AnatomyQuestion, CidUserAnswer, Exam)
|
||||
|
||||
class ExamClone(ExamCloneMixin, ExamCreate):
|
||||
"""Clone exam view"""
|
||||
|
||||
class StructureAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
# Don't forget to filter out results depending on the visitor !
|
||||
if not self.request.user.is_authenticated:
|
||||
return Structure.objects.none()
|
||||
|
||||
qs = Structure.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__istartswith=self.q)
|
||||
|
||||
return qs
|
||||
Reference in New Issue
Block a user