forms.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 Category, Expense, MultiplePaymentExepense, LoneExpense, RawExpense
  5. class CategoryForm(forms.ModelForm):
  6. class Meta:
  7. model = Category
  8. fields = "__all__"
  9. def __init__(self, *args, **kwargs):
  10. super().__init__(*args, **kwargs)
  11. class ExpenseForm(forms.ModelForm):
  12. class Meta:
  13. model = Expense
  14. fields = "__all__"
  15. def __init__(self, *args, **kwargs):
  16. super().__init__(*args, **kwargs)
  17. class MultiplePaymentExepenseForm(forms.ModelForm):
  18. class Meta:
  19. model = MultiplePaymentExepense
  20. fields = ("name", "first_payment_date", "amount", "number_of_payment", "category", "source")
  21. def __init__(self, *args, **kwargs):
  22. super().__init__(*args, **kwargs)
  23. class SubExpenseForm(forms.ModelForm):
  24. class Meta:
  25. model = RawExpense
  26. fields = ("amount",)
  27. def __init__(self, *args, **kwargs):
  28. super().__init__(*args, **kwargs)
  29. class LoneExpenseForm(forms.ModelForm):
  30. class Meta:
  31. model = LoneExpense
  32. fields = "__all__"
  33. def __init__(self, *args, **kwargs):
  34. super().__init__(*args, **kwargs)