From fd72594be84581ea46732d3a23bbb1dbc5716ec3 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 28 Nov 2021 17:05:15 +0000 Subject: [PATCH] . --- atlas/forms.py | 13 +++++++++++++ atlas/views.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atlas/forms.py b/atlas/forms.py index ba354fa1..83cc2c14 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -38,6 +38,19 @@ class SeriesFindingsForm(ModelForm): model = SeriesFindings exclude = [""] + def __init__(self, *args, **kwargs): + if kwargs.get("series_id"): + # We get the 'initial' keyword argument or initialize it + # as a dict if it didn't exist. + initial = kwargs.setdefault("initial", {}) + # The widget for a ModelMultipleChoiceField expects + # a list of primary key for the selected data. + initial["series"] = kwargs["series_id"].id + + super(SeriesFindingsForm, self).__init__(*args, **kwargs) + + ModelForm.__init__(self, *args, **kwargs) + class SeriesForm(ModelForm): class Media: # Django also includes a few javascript files necessary diff --git a/atlas/views.py b/atlas/views.py index 40568541..bb5c9936 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -117,7 +117,7 @@ def series_detail(request, pk): # if request.user not in atlas.author.all(): # raise PermissionDenied - series_finding_form = SeriesFindingsForm() + series_finding_form = SeriesFindingsForm(series_id=series.id) # logging.debug(atlas.subspecialty.first().name.all())