1👍
✅
You should pass *args
and **kwargs
when constructing your form.
def __init__(self, *args, **kwargs):
super(FantasySeasonForm,self).__init__(*args, **kwargs)
...
By missing out *args
, your current code has the same effect as if you did fantasyTeamForm = FantasySeasonForm(data=None)
. Even though there are no errors, is_valid()
returns False
because the form is not bound to any data.
As an aside, you can loop through the player fields to avoid repetition:
for player_id in xrange(1, 16)
field_name = "player%d" % player_id
self.fields[field_name].queryset = Player.objects.filter(team__competition__pk=2)
Source:stackexchange.com