Created
March 15, 2012 19:08
-
-
Save debuggerpk/2046119 to your computer and use it in GitHub Desktop.
shortlisting forms foriegn key based upon view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#views.py | |
def shortlist(request, team_id, fixture_id): | |
template = get_template('cricket/shortlist.html') | |
loggedinuser = request.user | |
userteam = Team.objects.get(owner=loggedinuser) | |
form = ShortlistForm | |
#get the players only belonging to this team_id | |
form.fields['player'].queryset = Player.objects.filter(team=userteam) | |
currentteam = Team.objects.get(id=team_id) | |
page_vars = Context({ | |
'form': form, | |
'loggedinuser': loggedinuser, | |
'team': userteam | |
}) | |
output = template.render(page_vars) | |
return HttpResponse(output) | |
#forms.py | |
class ShortlistForm(ModelForm): | |
class Meta: | |
model = PlayerShortlist | |
fields = ( | |
'player', | |
) | |
#urls.py | |
url(r'^team/(?P<team_id>\d+)/fixture/(?P<fixture_id>\d+)/shortlist/$', 'djangocricket.Cricket.views.shortlist'), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment