forms.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from django import forms
  2. from django.contrib.auth import get_user_model
  3. from dbsynce.models import ServiceType, Service, Orders, Resource
  4. from webservice_running.models import OrdersLocal
  5. from django.contrib.auth.forms import UserCreationForm
  6. class OrderRegForm(forms.ModelForm):
  7. class Meta:
  8. model = OrdersLocal
  9. fields = '__all__'
  10. def __init__(self, *args, **kwargs):
  11. super().__init__(*args, **kwargs)
  12. for field in self.fields.values():
  13. field.widget.attrs['class'] = 'form-control'
  14. class RegisterUserForm(UserCreationForm):
  15. password1 = forms.CharField(label="Пароль",
  16. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  17. password2 = forms.CharField(label="Подтверждение пароля",
  18. widget=forms.PasswordInput(attrs={'class':'form-control'}))
  19. username = forms.CharField(label="Номер телефона",
  20. widget=forms.TextInput(attrs={'class':'form-control'}))
  21. class Meta:
  22. model = get_user_model()
  23. fields = ['username', 'password1', 'password2']
  24. class OrderLocalForm(forms.ModelForm):
  25. order_synced = forms.ModelChoiceField(queryset = Orders.objects.all(), label="Заказ")
  26. resource_id = forms.ModelChoiceField(queryset = Resource.objects.all(), label="Ресурс")
  27. specialization = forms.CharField(label="Специализация рабочего места")
  28. address = forms.CharField(label="Адрес коворкинга")
  29. daily_price = forms.CharField(label="Стоимость в день")
  30. payment_transaction_id = forms.CharField(label="Транзакция платежа")
  31. attempts = forms.CharField(label="Попытка")
  32. order_place_type = forms.CharField(label="Тип заказа")
  33. def __init__(self, *args, **kwargs):
  34. super(OrderLocalForm, self).__init__(*args, **kwargs)
  35. class Meta:
  36. model = OrdersLocal
  37. fields = [
  38. 'order_synced',
  39. 'resource_id',
  40. 'specialization',
  41. 'address',
  42. 'daily_price',
  43. 'payment_transaction_id',
  44. 'attempts',
  45. 'order_place_type',
  46. ]
  47. #fields = '__all__'
  48. def __init__(self, *args, **kwargs):
  49. super().__init__(*args, **kwargs)
  50. for field in self.fields.values():
  51. field.widget.attrs['class'] = 'form-control'