1
0

forms.py 2.6 KB

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