.
This commit is contained in:
+11
-8
@@ -922,15 +922,8 @@ class PriorCaseForm(Form):
|
||||
# )
|
||||
|
||||
class CaseSeriesForm(forms.ModelForm):
|
||||
def __init__(self, *args, user=None, is_atlas_editor=False, **kwargs):
|
||||
def __init__(self, *args, queryset, user=None, is_atlas_editor=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not is_atlas_editor:
|
||||
queryset = Series.objects.filter(author__id=user.id)
|
||||
else:
|
||||
queryset = Series.objects.all()
|
||||
queryset = queryset.select_related("modality").prefetch_related(
|
||||
"examination", "plane", "contrast", "images"
|
||||
)
|
||||
self.fields["series"].queryset = queryset
|
||||
|
||||
class Meta:
|
||||
@@ -952,12 +945,22 @@ class CaseUpdateSeriesForm(forms.ModelForm):
|
||||
model = Case
|
||||
fields = [] # No fields, just for compatibility with UpdateView
|
||||
|
||||
class BaseSeriesFormSet(BaseInlineFormSet):
|
||||
def __init__(self, *args, queryset=None, **kwargs):
|
||||
self.series_queryset = queryset
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def get_form_kwargs(self, index):
|
||||
kwargs = super().get_form_kwargs(index)
|
||||
kwargs['queryset'] = self.series_queryset
|
||||
return kwargs
|
||||
|
||||
|
||||
SeriesFormSet = inlineformset_factory(
|
||||
Case,
|
||||
SeriesDetail,
|
||||
form=CaseSeriesForm,
|
||||
formset=BaseSeriesFormSet,
|
||||
extra=1,
|
||||
can_delete=True,
|
||||
)
|
||||
Reference in New Issue
Block a user