Commit ec7a6cdda4a9ece8520551f5f4bc71bc3ec86e8f
1 parent
d58bf804
Exists in
master
and in
5 other branches
adding validator to the link [Issue:#126]
Showing
1 changed file
with
8 additions
and
1 deletions
Show diff stats
links/forms.py
1 | 1 | from django import forms |
2 | 2 | from .models import Link |
3 | +import validators | |
3 | 4 | |
4 | 5 | class CreateLinkForm(forms.ModelForm): |
6 | + def validate_link(self,link): | |
7 | + if not validators.url(link): | |
8 | + raise forms.ValidationError(_('Please enter a valid URL')) | |
9 | + else: | |
10 | + return link | |
11 | + | |
5 | 12 | class Meta: |
6 | 13 | model = Link |
7 | 14 | fields = ['name','link','description'] |
8 | - | |
15 | + | |
9 | 16 | class UpdateLinkForm(forms.ModelForm): |
10 | 17 | class Meta: |
11 | 18 | model = Link | ... | ... |