.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from django.contrib.admin import widgets
|
||||
from django.forms import (
|
||||
Form,
|
||||
ModelForm,
|
||||
@@ -35,6 +36,15 @@ class SeriesFindingForm(ModelForm):
|
||||
model = SeriesFinding
|
||||
exclude = ["series", "annotation_json", "viewport_json"]
|
||||
|
||||
widgets = {
|
||||
"finding": autocomplete.ModelSelect2Multiple(
|
||||
url="atlas:finding-autocomplete"
|
||||
),
|
||||
"structure": autocomplete.ModelSelect2Multiple(
|
||||
url="atlas:struture-autocomplete"
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if kwargs.get("series_id"):
|
||||
# We get the 'initial' keyword argument or initialize it
|
||||
|
||||
+12
-1
@@ -1,6 +1,6 @@
|
||||
from django.urls import path, include
|
||||
|
||||
from atlas.models import Condition
|
||||
from atlas.models import Condition, Finding, Structure
|
||||
from . import views
|
||||
|
||||
app_name = "atlas"
|
||||
@@ -88,4 +88,15 @@ urlpatterns = [
|
||||
views.ConditionAutocomplete.as_view(model=Condition, create_field='structure'),
|
||||
name="condition-autocomplete",
|
||||
),
|
||||
path(
|
||||
"finding-autocomplete",
|
||||
views.ConditionAutocomplete.as_view(model=Finding, create_field='finding'),
|
||||
name="finding-autocomplete",
|
||||
),
|
||||
path(
|
||||
"structure-autocomplete",
|
||||
views.ConditionAutocomplete.as_view(model=Structure, create_field='structure'),
|
||||
name="structure-autocomplete",
|
||||
),
|
||||
|
||||
]
|
||||
|
||||
@@ -41,6 +41,7 @@ from .models import (
|
||||
Series,
|
||||
Examination,
|
||||
Finding,
|
||||
Structure,
|
||||
Subspecialty,
|
||||
SeriesFinding,
|
||||
SeriesImage,
|
||||
@@ -599,3 +600,37 @@ class ConditionAutocomplete(autocomplete.Select2QuerySetView):
|
||||
return Condition.objects.none()
|
||||
|
||||
return qs
|
||||
|
||||
class FindingAutocomplete(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 Finding.objects.none()
|
||||
|
||||
qs = Finding.objects.all()
|
||||
|
||||
if self.q:
|
||||
# This raises a fielderror which breaks creating a new item if not caught
|
||||
try:
|
||||
qs = qs.filter(name__contains=self.q)
|
||||
except FieldError:
|
||||
return Finding.objects.none()
|
||||
|
||||
return qs
|
||||
|
||||
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:
|
||||
# This raises a fielderror which breaks creating a new item if not caught
|
||||
try:
|
||||
qs = qs.filter(name__contains=self.q)
|
||||
except FieldError:
|
||||
return Structure.objects.none()
|
||||
|
||||
return qs
|
||||
Reference in New Issue
Block a user