Skip to content

Instantly share code, notes, and snippets.

@debuggerpk
Created March 17, 2012 15:41
Show Gist options
  • Save debuggerpk/2061323 to your computer and use it in GitHub Desktop.
Save debuggerpk/2061323 to your computer and use it in GitHub Desktop.
How to call object in formset_factory based upon a view (solved).
#forms.py
def make_innings_form(teamid, fixtureid):
class InningsForm(forms.Form):
player = forms.ModelChoiceField(PlayerShortlist.objects.filter(
team = teamid,
fixture = fixtureid
)
)
status = forms.ChoiceField(choices=OUT_CHOICES, initial='DNB')
score = forms.IntegerField(initial=0)
balls_faced = forms.IntegerField(initial=0)
return InningsForm
#views.py
@login_required
def scorecard(request, team_id, fixture_id):
template = get_template('scorecard.html')
tossform = TossForm()
inningsforms = formset_factory(
make_innings_form(team_id, fixture_id),
extra=11,
)
page_vars = Context({
'loggedinuser': request.user,
'tossform': tossform,
'inningsforms': inningsforms,
})
crsfcontext = RequestContext(request, page_vars)
output = template.render(crsfcontext)
return HttpResponse(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment