Нема описа

forms.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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
  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. GeneralWidgets = {
  9. 'startDate': forms.DateInput(format="%d/%m/%Y",attrs={'type': 'text', 'class': 'datepicker'}),
  10. 'address': map_widgets.GoogleMapsAddressWidget,
  11. 'photo': forms.FileInput,
  12. 'sub_total': forms.TextInput(attrs={'readonly': 'readonly'}),
  13. 'vat': forms.TextInput(attrs={'readonly': 'readonly'}),
  14. 'total': forms.TextInput(attrs={'readonly': 'readonly'}),
  15. }
  16. StoreForm = modelform_factory(
  17. Store,
  18. fields="__all__",
  19. widgets = GeneralWidgets,
  20. )
  21. ProductSKUForm = modelform_factory(
  22. ProductSKU,
  23. fields="__all__",
  24. widgets = GeneralWidgets,
  25. )
  26. ProductForm = modelform_factory(
  27. Product,
  28. fields="__all__",
  29. exclude = ("store", ),
  30. widgets = GeneralWidgets,
  31. )
  32. SaleForm = modelform_factory(
  33. Sale,
  34. fields="__all__",
  35. #exclude = ("store", ),
  36. widgets = GeneralWidgets,
  37. )
  38. InboxForm = modelform_factory(
  39. Inbox,
  40. fields="__all__",
  41. #exclude = ("store", ),
  42. widgets = GeneralWidgets,
  43. )
  44. PhotoFormSet = modelformset_factory(
  45. Photo,
  46. fields="__all__",
  47. exclude = ("product", ),
  48. #extra = 3,
  49. widgets = GeneralWidgets,
  50. )
  51. InlinePhotoFormset = inlineformset_factory(Product, Photo, fields="__all__", widgets= GeneralWidgets)
  52. class ProductFilter(django_filters.FilterSet):
  53. class Meta:
  54. model = Product
  55. fields = ['name', 'code', 'price']
  56. class SaleFilter(django_filters.FilterSet):
  57. class Meta:
  58. model = Sale
  59. fields = ['product', 'sku', 'buyer', 'n_unit', 'unit_name']
  60. class InboxFilter(django_filters.FilterSet):
  61. class Meta:
  62. model = Inbox
  63. fields = ['store', 'product', 'buyer', 'subject', 'body', 'tel', 'status', 'created_at']