1
0

forms.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from django import forms
  2. from django.contrib.auth import get_user_model
  3. from webservice_running.models import OrdersLocal
  4. from django.contrib.auth.forms import UserCreationForm
  5. GUIDE_TYPE = [
  6. ('one', '1'),
  7. ('two', '2'),
  8. ('three', '3'),
  9. ]
  10. MOVEMENT_WAY = [
  11. ('one', 'Автобус'),
  12. ('two', 'Машина'),
  13. ('three', 'Пешком'),
  14. ]
  15. class OrderRegForm(forms.ModelForm):
  16. place_start = forms.CharField(label="Точка 1")
  17. place_end = forms.CharField(label="Точка 2")
  18. guide_type = forms.ChoiceField(choices=GUIDE_TYPE, label="Тип гида")
  19. movement_way = forms.ChoiceField(choices=MOVEMENT_WAY, label="Вид передвижения")
  20. numb_of_people = forms.IntegerField(label="Количество человек")
  21. service_date = forms.DateField(label="Дата", help_text=datetime.date.today)
  22. service_time = forms.TimeField(label="Время")
  23. discription = forms.CharField(label="Пожелания")
  24. price = forms.IntegerField(label="Предварительная стоимость")
  25. class Meta:
  26. model = OrdersLocal
  27. fields = ['place_start', 'place_end', 'guide_type', 'movement_way', 'numb_of_people', 'service_date', 'service_time', 'discription', 'price']
  28. def __init__(self, *args, **kwargs):
  29. super().__init__(*args, **kwargs)
  30. for field in self.fields.values():
  31. field.widget.attrs['class'] = 'form-control'
  32. class RegisterUserForm(UserCreationForm):
  33. password1 = forms.CharField(label="Пароль",
  34. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  35. password2 = forms.CharField(label="Подтверждение пароля",
  36. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  37. phone_number = forms.CharField(label="Номер телефона",
  38. widget=forms.TextInput(attrs={'class':'form-control'}))
  39. email = forms.CharField(label="Email",
  40. widget=forms.TextInput(attrs={'class':'form-control'}))
  41. username = forms.CharField(label="Имя пользователя",
  42. widget=forms.TextInput(attrs={'class':'form-control'}))
  43. first_name = forms.CharField(label="Имя",
  44. widget=forms.TextInput(attrs={'class':'form-control'}))
  45. last_name = forms.CharField(label="Фамилия",
  46. widget=forms.TextInput(attrs={'class':'form-control'}))
  47. class Meta:
  48. model = get_user_model()
  49. fields = ['username', 'first_name', 'last_name', 'avatar', 'phone_number', "email", 'password1', 'password2' ]