1
0

forms.py 2.5 KB

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