Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. from django.forms import ModelForm
  2. from django import forms
  3. from models import Contacts
  4.  
  5. class ContactForm(forms.Form):
  6. class Meta:
  7. model = Contacts
  8.  
  9. name = forms.CharField(max_length=30)
  10. email = forms.EmailField(max_length=254)
  11. message = forms.CharField(
  12. max_length=2000,
  13. widget=forms.Textarea(),
  14. help_text='Write here your message!'
  15. )
  16.  
  17. def clean(self):
  18. cleaned_data = super(ContactForm, self).clean()
  19. name = cleaned_data.get('name')
  20. email = cleaned_data.get('email')
  21. message = cleaned_data.get('message')
  22. if not name and not email and not message:
  23. raise forms.ValidationError('You have to write something!')
  24.  
  25. def addcontact(request):
  26. if request.POST:
  27. form_c = ContactForm(request.POST)
  28. if form_c.is_valid():
  29. f.save() # не работает т.к. у ContactForm нет этого метода
  30. return HttpResponseRedirect('/contacts/thanks/')
  31. else:
  32. form_c = ContactForm()
  33. return render(request, 'contacts.html', {'form_c': form_c})
Add Comment
Please, Sign In to add comment