Sin descripción

forms.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from django.forms.models import inlineformset_factory, modelform_factory, modelformset_factory
  2. from django import forms
  3. from .models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorOrder, VendorProduct, Profile
  4. from django.forms import ModelForm
  5. from django_google_maps import widgets as map_widgets
  6. from django_google_maps import fields as map_fields
  7. import django_filters
  8. from django.contrib.auth.forms import UserCreationForm
  9. from django.contrib.auth.models import User
  10. GeneralWidgets = {
  11. 'startDate': forms.DateInput(format="%d/%m/%Y",attrs={'type': 'text', 'class': 'datepicker'}),
  12. 'address': map_widgets.GoogleMapsAddressWidget,
  13. 'photo': forms.FileInput,
  14. 'sub_total': forms.TextInput(attrs={'readonly': 'readonly'}),
  15. 'vat': forms.TextInput(attrs={'readonly': 'readonly'}),
  16. 'total': forms.TextInput(attrs={'readonly': 'readonly'}),
  17. }
  18. StoreForm = modelform_factory(
  19. Store,
  20. fields="__all__",
  21. widgets = GeneralWidgets,
  22. )
  23. ProfileForm = modelform_factory(
  24. Profile,
  25. fields=("bio", "location", "facebook", "line_id", "tel", ),
  26. widgets = GeneralWidgets,
  27. )
  28. UserForm = modelform_factory(
  29. User,
  30. fields=("first_name", "last_name"),
  31. widgets = GeneralWidgets,
  32. )
  33. ProductSKUForm = modelform_factory(
  34. ProductSKU,
  35. fields="__all__",
  36. widgets = GeneralWidgets,
  37. )
  38. ProductForm = modelform_factory(
  39. Product,
  40. fields="__all__",
  41. exclude = ("store", ),
  42. widgets = GeneralWidgets,
  43. )
  44. SaleForm = modelform_factory(
  45. Sale,
  46. fields="__all__",
  47. #exclude = ("store", ),
  48. widgets = GeneralWidgets,
  49. )
  50. InboxForm = modelform_factory(
  51. Inbox,
  52. fields="__all__",
  53. #exclude = ("store", ),
  54. widgets = GeneralWidgets,
  55. )
  56. VendorForm = modelform_factory(
  57. Vendor,
  58. fields="__all__",
  59. exclude = ("store", ),
  60. widgets = GeneralWidgets,
  61. )
  62. VendorProductForm = modelform_factory(
  63. VendorProduct,
  64. fields="__all__",
  65. exclude = ("store", "vendor"),
  66. widgets = GeneralWidgets,
  67. )
  68. VendorOrderForm = modelform_factory(
  69. VendorOrder,
  70. fields="__all__",
  71. exclude = ("store", ),
  72. widgets = GeneralWidgets,
  73. )
  74. PhotoFormSet = modelformset_factory(
  75. Photo,
  76. fields="__all__",
  77. exclude = ("product", ),
  78. #extra = 3,
  79. widgets = GeneralWidgets,
  80. )
  81. InlinePhotoFormset = inlineformset_factory(Product, Photo, fields="__all__", widgets= GeneralWidgets)
  82. InlineVendorProductFormset = inlineformset_factory(Vendor, VendorProduct, fields="__all__", widgets= GeneralWidgets)
  83. class ProductFilter(django_filters.FilterSet):
  84. class Meta:
  85. model = Product
  86. fields = ['name', 'code', 'price']
  87. class SaleFilter(django_filters.FilterSet):
  88. class Meta:
  89. model = Sale
  90. fields = ['product', 'sku', 'buyer', 'n_unit', 'unit_name']
  91. class InboxFilter(django_filters.FilterSet):
  92. class Meta:
  93. model = Inbox
  94. fields = ['store', 'product', 'buyer', 'subject', 'body', 'tel', 'status', 'created_at']
  95. class VendorFilter(django_filters.FilterSet):
  96. class Meta:
  97. model = Vendor
  98. fields = ['name', 'code', 'description', 'tel', 'line_id', 'email', 'created_at']
  99. class VendorOrderFilter(django_filters.FilterSet):
  100. class Meta:
  101. model = VendorOrder
  102. fields = ['vendor', 'product', 'store', 'price', 'n_unit', 'unit_name', 'total', 'created_at']
  103. class SignUpForm(UserCreationForm):
  104. #email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
  105. roles = forms.ChoiceField(choices = (("seller", "Seller"), ("buyer", "Buyer")))
  106. class Meta:
  107. model = User
  108. fields = ('username', 'email', 'password1', 'password2', 'roles', )