Hey guys, My problem is similar to http://stackoverflow.com/questions/622982/django-passing-custom-form-parameters-to-formset/624013
Ive have these classes
class Game(models.Model):
home_team = models.ForeignKey(Team, related_name='home_team')
away_team = models.ForeignKey(Team, related_name='away_team')
round = models.ForeignKey(Round)
TEAM_CHOICES = ((1, '1'), (2, 'X'), (3, '2'),)
class Odds(models.Model):
game = models.ForeignKey(Game, unique=False)
team = models.IntegerField(choices = TEAM_CHOICES)
odds = models.FloatField()
class Meta:
verbose_name_plural = "Odds"
unique_together = (
("game", "team"),
)
class Vote(models.Model):
user = models.ForeignKey(User, unique=False)
game = models.ForeignKey(Game)
score = models.ForeignKey(Odds)
class Meta:
unique_together = (
("game", "user"),)
And I've defined my own modelformset_factory:
def mymodelformset_factory(ins):
class VoteForm(forms.ModelForm):
score = forms.ModelChoiceField(queryset=Odds.objects.filter(game=ins), widget=forms.RadioSelect(), empty_label=None)
def __init__(self, *args, **kwargs):
super(VoteForm, self).__init__(*args, **kwargs)
class Meta:
model = Vote
exclude = ['user']
return VoteForm
And I use it like this:
VoteFormSet = modelformset_factory(Vote, form=mymodelformset_factory(v), extra=0)
formset = VoteFormSet(request.POST, queryset=Vote.objects.filter(game__round=round, user=user))
This displays the form:
drop down box of Game(s) in the Round specified and is supposed to display 3 radio buttons for the Odds but I don't know what to pass as a parameter to the mymodelformset_factory.. If v = Game.objects.get(pk=1) it obviously only displays Game with pk=1 for ALL Games, What I need is v = Game.objects.get(pk="game who is connected to the odds regarding") if you catch my drift..