many Longs fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.forms import (
|
||||
BaseInlineFormSet,
|
||||
Form,
|
||||
ModelForm,
|
||||
ModelMultipleChoiceField,
|
||||
@@ -20,6 +21,9 @@ from longs.models import (
|
||||
Exam,
|
||||
)
|
||||
|
||||
from django.db.models import Prefetch
|
||||
|
||||
|
||||
from anatomy.models import Modality
|
||||
|
||||
from generic.models import Examination#, Condition, Sign
|
||||
@@ -174,9 +178,11 @@ class LongForm(ModelForm):
|
||||
# a list of primary key for the selected data.
|
||||
initial["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||
|
||||
|
||||
ModelForm.__init__(self, *args, **kwargs)
|
||||
|
||||
super(LongForm, self).__init__(*args, **kwargs)
|
||||
print(self.fields)
|
||||
|
||||
if self.user.groups.filter(name="long_checker").exists():
|
||||
exam_queryset = Exam.objects.all()
|
||||
@@ -245,14 +251,44 @@ class LongForm(ModelForm):
|
||||
|
||||
return instance
|
||||
|
||||
#class CustomInlineFormSet(BaseInlineFormSet):
|
||||
# def get_queryset(self):
|
||||
# if not hasattr(self, '_queryset'):
|
||||
# qs = super(CustomInlineFormSet, self).get_queryset()#.values()
|
||||
# self._queryset = qs
|
||||
# return self._queryset
|
||||
|
||||
#class LongForm(ModelForm):
|
||||
class CaseSeriesForm(ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super(CaseSeriesForm, self).__init__(*args, **kwargs)
|
||||
ModelForm.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
# We can limit the series available to choose from here
|
||||
# as well a dramatically reducing the sql queries
|
||||
queryset = LongSeries.objects.select_related("modality", "examination", "plane").prefetch_related("long").all()#.filter(pk=62)#.values()
|
||||
self.fields["longseries"] = ModelChoiceField(queryset=queryset)
|
||||
|
||||
class Meta:
|
||||
model = LongSeries.long.through
|
||||
#fields = [ modality ]
|
||||
#exclude = []
|
||||
fields = ["longseries", "sort_value"]
|
||||
|
||||
|
||||
|
||||
|
||||
SeriesFormSet = inlineformset_factory(
|
||||
Long,
|
||||
LongSeries.long.through,
|
||||
form=CaseSeriesForm,
|
||||
exclude=[],
|
||||
can_delete=True,
|
||||
extra=0,
|
||||
max_num=10,
|
||||
#formset=CustomInlineFormSet
|
||||
)
|
||||
|
||||
LongSeriesImageFormSet = inlineformset_factory(
|
||||
|
||||
Reference in New Issue
Block a user