def has_same_contact(self, exist_contact): phone = self.cleaned_data['phone'] email = self.cleaned_data['email'] exist_phone = get_phone(exist_contact.phone) exist_email = exist_contact.email return True if phone == exist_phone and email == exist_email else False
def clean_phone(self): clean_phone = self.data.get('phone') or '' phone = get_phone(clean_phone) if not phone: raise forms.ValidationError('电话号码有误') return phone