diff options
-rw-r--r-- | archaeological_context_records/forms.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index f4c20d55a..44d89fcf1 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -702,6 +702,7 @@ class QAContextRecordFormMulti(QAForm): "qa_related_to": models.ContextRecord, "qa_unit": models.Unit, "qa_town": models.Town, + "qa_parcel": models.Parcel, } REPLACE_FIELDS = [ "qa_unit", @@ -739,12 +740,36 @@ class QAContextRecordFormMulti(QAForm): ), required=False ) + qa_parcel = forms.ChoiceField( + label=_("Associated parcel"), choices=[], required=False + ) + # qa_parcel.choices += [ + # (p.pk, str(p)) for p in Parcel.objects.all() + # ] TYPES = [ FieldType("qa_relation_type", models.RelationType), FieldType("qa_unit", models.Unit), ] + def __init__(self, *args, **kwargs): + super(QAContextRecordFormMulti, self).__init__(*args, **kwargs) + self.items = kwargs.pop("items") + op_pk = 0 + disable = False + for cr in self.items: + if op_pk != cr.operation.pk and op_pk > 0: + disable = self.fields["qa_parcel"].disabled = True + break + op_pk = cr.operation.pk + if not disable: + self.fields["qa_parcel"].choices += [ + (p.pk, str(p)) for p in Parcel.objects.filter( + operation=self.items[-1].operation.pk + ).all() + ] + + def clean(self): cleaned_data = super().clean() r_type = cleaned_data.get("qa_relation_type") |