Fix issue where you couldn't edit your canonical domain.
This logic was checking to see if the domain passed in was the current canonical,
but using the domain you were _trying_ to change it to.
We should be checking for the existing PK to see if you're editing,
not the new domain.
@@ -570,9 +570,10 @@ class DomainForm(forms.ModelForm):
def clean_canonical(self):
canonical = self.cleaned_data['canonical']
+ _id = self.initial.get('id')
if canonical and Domain.objects.filter(
- project=self.project, canonical=True).exclude(
- domain=self.cleaned_data['domain']).exists():
+ project=self.project, canonical=True
+ ).exclude(pk=_id).exists():
raise forms.ValidationError(
_('Only 1 Domain can be canonical at a time.'))
return canonical
