forms.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from django import forms
  2. from django.contrib.auth.models import User
  3. from django.core.exceptions import ValidationError
  4. from expenses.models import (
  5. Category,
  6. Expense,
  7. MultiplePaymentExepense,
  8. LoneExpense,
  9. RawExpense,
  10. )
  11. class CategoryForm(forms.ModelForm):
  12. class Meta:
  13. model = Category
  14. fields = "__all__"
  15. def __init__(self, *args, **kwargs):
  16. super().__init__(*args, **kwargs)
  17. class ExpenseForm(forms.Form):
  18. is_multiple_payment = forms.BooleanField(
  19. label="Is mulptiple payment", initial=False
  20. )
  21. class MultiplePaymentExepenseForm(forms.ModelForm):
  22. class Meta:
  23. model = MultiplePaymentExepense
  24. fields = (
  25. "name",
  26. "date",
  27. "amount",
  28. "number_of_payment",
  29. "category",
  30. "source",
  31. )
  32. first_payment_amount = forms.DecimalField(max_digits=10, decimal_places=2)
  33. def __init__(self, *args, **kwargs):
  34. super().__init__(*args, **kwargs)
  35. class SubExpenseForm(forms.ModelForm):
  36. class Meta:
  37. model = RawExpense
  38. fields = ("amount",)
  39. def __init__(self, *args, **kwargs):
  40. super().__init__(*args, **kwargs)
  41. class LoneExpenseForm(forms.ModelForm):
  42. class Meta:
  43. model = LoneExpense
  44. fields = (
  45. "name",
  46. "date",
  47. "amount",
  48. "category",
  49. "source",
  50. )
  51. def __init__(self, *args, **kwargs):
  52. super().__init__(*args, **kwargs)