filter form
This commit is contained in:
@@ -1230,6 +1230,12 @@ class RaceResultFilterForm(forms.Form):
|
||||
initial=['None','PR1','PR2','PR3','FES'],
|
||||
widget=forms.CheckboxSelectMultiple())
|
||||
|
||||
entrycategory = forms.MultipleChoiceField(
|
||||
choices = [],
|
||||
label = 'Groups',
|
||||
widget=forms.CheckboxSelectMultiple()
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'records' in kwargs:
|
||||
records = kwargs.pop('records',None)
|
||||
@@ -1237,6 +1243,21 @@ class RaceResultFilterForm(forms.Form):
|
||||
super(RaceResultFilterForm,self).__init__(*args,**kwargs)
|
||||
|
||||
if records:
|
||||
# group
|
||||
thecategories = [record.entrycategory for record in records]
|
||||
thecategories = list(set(thecategories))
|
||||
if len(thecategories) <= 1:
|
||||
del self.fields['entrycategory']
|
||||
else:
|
||||
categorychoices = []
|
||||
for category in thecategories:
|
||||
if category is not None:
|
||||
categorychoices.append(
|
||||
(category.id,category)
|
||||
)
|
||||
self.fields['entrycategory'].choices = categorychoices
|
||||
self.fields['entrycategory'].initial = [cat[0] for cat in categorychoices]
|
||||
|
||||
# sex
|
||||
thesexes = [record.sex for record in records]
|
||||
thesexes = list(set(thesexes))
|
||||
|
||||
Reference in New Issue
Block a user