.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from django.contrib.admin import widgets
|
||||||
from django.forms import (
|
from django.forms import (
|
||||||
Form,
|
Form,
|
||||||
ModelForm,
|
ModelForm,
|
||||||
@@ -35,6 +36,15 @@ class SeriesFindingForm(ModelForm):
|
|||||||
model = SeriesFinding
|
model = SeriesFinding
|
||||||
exclude = ["series", "annotation_json", "viewport_json"]
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
if kwargs.get("series_id"):
|
if kwargs.get("series_id"):
|
||||||
# We get the 'initial' keyword argument or initialize it
|
# We get the 'initial' keyword argument or initialize it
|
||||||
|
|||||||
+12
-1
@@ -1,6 +1,6 @@
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from atlas.models import Condition
|
from atlas.models import Condition, Finding, Structure
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name = "atlas"
|
app_name = "atlas"
|
||||||
@@ -88,4 +88,15 @@ urlpatterns = [
|
|||||||
views.ConditionAutocomplete.as_view(model=Condition, create_field='structure'),
|
views.ConditionAutocomplete.as_view(model=Condition, create_field='structure'),
|
||||||
name="condition-autocomplete",
|
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,
|
Series,
|
||||||
Examination,
|
Examination,
|
||||||
Finding,
|
Finding,
|
||||||
|
Structure,
|
||||||
Subspecialty,
|
Subspecialty,
|
||||||
SeriesFinding,
|
SeriesFinding,
|
||||||
SeriesImage,
|
SeriesImage,
|
||||||
@@ -599,3 +600,37 @@ class ConditionAutocomplete(autocomplete.Select2QuerySetView):
|
|||||||
return Condition.objects.none()
|
return Condition.objects.none()
|
||||||
|
|
||||||
return qs
|
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