116 lines
4.0 KiB
Python
116 lines
4.0 KiB
Python
from django import forms
|
|
from .models import Transaction, Account, Category, Transfer
|
|
from django.forms.models import modelform_factory, modelformset_factory, BaseModelFormSet
|
|
from django.forms.formsets import formset_factory
|
|
from django.forms.extras.widgets import SelectDateWidget
|
|
from django.forms.widgets import SplitDateTimeWidget, DateInput, TextInput
|
|
from django.contrib.admin.widgets import AdminSplitDateTime
|
|
|
|
|
|
class NewTransactionExp (forms.ModelForm):
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
user = kwargs.pop('user', None)
|
|
type = kwargs.pop('type', None)
|
|
super(NewTransactionExp, self).__init__(*args, **kwargs)
|
|
self.fields['tr_acc'].queryset=Account.objects.filter(user=user)
|
|
self.fields['tr_cat'].queryset=Category.objects.filter(user=user, cat_type='E')
|
|
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ('tr_type', 'tr_date', 'tr_acc', 'tr_cat', 'tr_amount', 'tr_note',)
|
|
widgets = {
|
|
'tr_amount': TextInput()
|
|
}
|
|
|
|
|
|
class NewTransactionInc (forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
user = kwargs.pop('user', None)
|
|
type = kwargs.pop('type', None)
|
|
super(NewTransactionInc, self).__init__(*args, **kwargs)
|
|
self.fields['tr_acc'].queryset=Account.objects.filter(user=user)
|
|
self.fields['tr_cat'].queryset=Category.objects.filter(user=user, cat_type='I')
|
|
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ('tr_type', 'tr_date', 'tr_acc', 'tr_cat', 'tr_amount', 'tr_note',)
|
|
widgets = {
|
|
'tr_amount': TextInput()
|
|
}
|
|
|
|
class NewTransaction (forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
user = kwargs.pop('user', None)
|
|
#type = kwargs.pop('type', None)
|
|
super(NewTransaction, self).__init__(*args, **kwargs)
|
|
self.fields['tr_acc'].queryset=Account.objects.filter(user=user)
|
|
self.fields['tr_cat'].queryset=Category.objects.filter(user=user)
|
|
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ('tr_type', 'tr_date', 'tr_acc', 'tr_cat', 'tr_amount', 'tr_note',)
|
|
widgets = {
|
|
'tr_amount': TextInput()
|
|
}
|
|
|
|
|
|
class NewTransaction1 (forms.ModelForm):
|
|
|
|
tr_acc = forms.ModelChoiceField( queryset=Account.objects.filter(user=3))
|
|
tr_cat = forms.ModelChoiceField( queryset=Category.objects.filter(user=3))
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ('tr_date', 'tr_acc', 'tr_type', 'tr_cat', 'tr_amount', 'tr_note',)
|
|
widgets = {
|
|
'tr_amount': TextInput()
|
|
}
|
|
|
|
class BaseTransactionFormSet(BaseModelFormSet):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
user = kwargs.pop('user', None)
|
|
super(BaseTransactionFormSet, self).__init__(*args, **kwargs)
|
|
self.fields['tr_acc'].queryset=Account.objects.filter(user=user)
|
|
self.fields['tr_cat'].queryset=Category.objects.filter(user=user)
|
|
self.queryset = Transaction.objects.filter(user=user)
|
|
|
|
|
|
class NewAccount(forms.ModelForm):
|
|
class Meta:
|
|
model = Account
|
|
fields = ('acc_name', 'acc_balance', 'acc_currency',)
|
|
|
|
class NewCategory(forms.ModelForm):
|
|
|
|
class Meta:
|
|
model = Category
|
|
#forms = '__all__'
|
|
exclude = ('user',)
|
|
#fields = ('cat_name', 'budget_amount', 'budget_type')
|
|
|
|
class NewTransfer(forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
user = kwargs.pop('user', None)
|
|
super(NewTransfer, self).__init__(*args, **kwargs)
|
|
self.fields['from_acc'].queryset=Account.objects.filter(user=user)
|
|
self.fields['to_acc'].queryset=Account.objects.filter(user=user)
|
|
|
|
class Meta:
|
|
model = Transfer
|
|
exclude = ('user',)
|
|
forms = '__all__'
|
|
|
|
class Upload (forms.ModelForm):
|
|
|
|
class Meta:
|
|
model = Transaction
|
|
fields = []
|
|
|
|
#Cat_formset = modelformset_factory(Category, form=NewCategory, extra=0)
|
|
#TestTrModel = modelformset_factory(Transaction, form=NewTransaction, can_delete=True, extra=0)
|