diff --git a/pinry/pins/forms.py b/pinry/pins/forms.py index 21f929a..c3175fd 100644 --- a/pinry/pins/forms.py +++ b/pinry/pins/forms.py @@ -8,11 +8,15 @@ class PinForm(forms.ModelForm): def clean_url(self): data = self.cleaned_data['url'] - image_file_types = ['png', 'gif', 'jpeg', 'jpg'] - file_type = data.split('.')[-1] - if file_type.lower() not in image_file_types: - raise forms.ValidationError("Requested URL is not an image file. Only images are currently supported.") - return data + try: + Pin.objects.get(url=data) + raise forms.ValidationError("URL has already been pinned!") + except Pin.DoesNotExist: + image_file_types = ['png', 'gif', 'jpeg', 'jpg'] + file_type = data.split('.')[-1] + if file_type.lower() not in image_file_types: + raise forms.ValidationError("Requested URL is not an image file. Only images are currently supported.") + return data class Meta: model = Pin