summaryrefslogtreecommitdiff
path: root/archaeological_context_records/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r--archaeological_context_records/forms.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 36f6ea516..75b6d71ef 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -935,17 +935,18 @@ class QADating(ManageOldType, forms.Form):
def clean(self):
data = self.cleaned_data
reference = data['reference']
- q_attr = {
- "reference": reference,
- self.dating_model.CURRENT_MODEL_ATTR + "_id": self.current_item.pk
- }
- q = self.dating_model.objects.filter(**q_attr)
- if data.get("pk", None):
- q = q.exclude(pk=data["pk"])
- if q.count():
- raise forms.ValidationError(
- _("This reference already exists for this item.")
- )
+ if reference:
+ q_attr = {
+ "reference": reference,
+ self.dating_model.CURRENT_MODEL_ATTR + "_id": self.current_item.pk
+ }
+ q = self.dating_model.objects.filter(**q_attr)
+ if data.get("pk", None):
+ q = q.exclude(pk=data["pk"])
+ if q.count():
+ raise forms.ValidationError(
+ _("This reference already exists for this item.")
+ )
if any(1 for k in self.cleaned_data if self.cleaned_data[k]):
return data
raise forms.ValidationError(_("No data provided."))