.
This commit is contained in:
@@ -100,6 +100,7 @@ class CidUserForm(ModelForm):
|
|||||||
# The widget for a ModelMultipleChoiceField expects
|
# The widget for a ModelMultipleChoiceField expects
|
||||||
# a list of primary key for the selected data.
|
# a list of primary key for the selected data.
|
||||||
initial["physics_exams"] = [t.pk for t in kwargs["instance"].physics_exams.all()]
|
initial["physics_exams"] = [t.pk for t in kwargs["instance"].physics_exams.all()]
|
||||||
|
initial["anatomy_exams"] = [t.pk for t in kwargs["instance"].anatomy_exams.all()]
|
||||||
|
|
||||||
ModelForm.__init__(self, *args, **kwargs)
|
ModelForm.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
@@ -110,6 +111,11 @@ class CidUserForm(ModelForm):
|
|||||||
queryset=PhysicsExam.objects.filter(archive=False),
|
queryset=PhysicsExam.objects.filter(archive=False),
|
||||||
widget=FilteredSelectMultiple(verbose_name="Physics Exams", is_stacked=False),
|
widget=FilteredSelectMultiple(verbose_name="Physics Exams", is_stacked=False),
|
||||||
)
|
)
|
||||||
|
self.fields["anatomy_exams"] = ModelMultipleChoiceField(
|
||||||
|
required=False,
|
||||||
|
queryset=AnatomyExam.objects.filter(archive=False),
|
||||||
|
widget=FilteredSelectMultiple(verbose_name="Anatomy Exams", is_stacked=False),
|
||||||
|
)
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
# Get the unsaved Long instance
|
# Get the unsaved Long instance
|
||||||
@@ -124,6 +130,10 @@ class CidUserForm(ModelForm):
|
|||||||
for physics_exams in self.cleaned_data["physics_exams"]:
|
for physics_exams in self.cleaned_data["physics_exams"]:
|
||||||
# We need the id here
|
# We need the id here
|
||||||
instance.physics_exams.add(physics_exams.pk)
|
instance.physics_exams.add(physics_exams.pk)
|
||||||
|
instance.anatomy_exams.clear()
|
||||||
|
for anatomy_exams in self.cleaned_data["anatomy_exams"]:
|
||||||
|
# We need the id here
|
||||||
|
instance.anatomy_exams.add(anatomy_exams.pk)
|
||||||
|
|
||||||
self.save_m2m = save_m2m
|
self.save_m2m = save_m2m
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user