Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

from dal import autocomplete 

 

from django import forms 

from .models import Transaction 

from members.models import Member 

from paginated_modelformset import PaginatedModelFormSet 

 

 

class MemberModelChoiceField(forms.ModelChoiceField): 

def label_from_instance(self, item): 

"""How the member object is displayed in the field's box once it's selected""" 

return "{}: {} {} ({})".format(item.chaos_number, item.first_name, item.last_name, 

"active" if item.is_active else "inactive") 

 

 

class TransactionForm(forms.ModelForm): 

def __init__(self, *args, **kwargs): 

super(TransactionForm, self).__init__(*args, **kwargs) 

self.fields['information'].disabled = True 

self.fields['information'].required = False 

self.fields['payer'].disabled = True 

self.fields['amount'].disabled = True 

 

member = MemberModelChoiceField( 

queryset=Member.objects.all(), 

widget=autocomplete.ModelSelect2(url='import_app:member_autocomplete'), 

required=False 

) 

 

class Meta: 

model = Transaction 

fields = ['information', 'member', 'payer', 'amount', 'status'] 

readonly = ['information', 'payer', 'amount'] 

 

 

TransactionFormSet = forms.modelformset_factory(Transaction, extra=0, form=TransactionForm, 

formset=PaginatedModelFormSet)