12311k

Untitled

Mar 7th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. forms.py
  2. ________
  3. from django import forms
  4.  
  5. from .models import GENRE_CHOICES, CD
  6.  
  7.  
  8. class ExchangeForm(forms.Form):
  9. name = forms.CharField(label="Ваше имя", max_length=100)
  10. email = forms.EmailField(label="Электронная почта для обратной связи")
  11. title = forms.CharField(label="Название альбома", max_length=100)
  12. artist = forms.CharField(label="Исполнитель", max_length=40)
  13. genre = forms.ChoiceField(label="Жанр", choices=GENRE_CHOICES)
  14. price = forms.DecimalField(label="Стоимость", required=False)
  15. comment = forms.CharField(label="Комментарий", widget=forms.Textarea, required=False)
  16.  
  17. def clean_artist(self):
  18. artist = self.cleaned_data["artist"]
  19.  
  20. if not CD.objects.filter(artist__iexact=artist).exists():
  21. raise forms.ValidationError(
  22. "Диски этого артиста мы не собираем!", params={"artist": artist},
  23. )
  24.  
  25. return artist
Advertisement
Add Comment
Please, Sign In to add comment