无法将初始数据传递给formset

时间:2014-03-21 20:19:51

标签: django formset

在我的Django应用程序中,我有以下内容:

形式:

class GameForm(forms.ModelForm):  

    class Meta:
        model = Game

    def __init__(self, *args, **kwargs):
        super(GameForm, self).__init__(*args, **kwargs)
        curr_tournament = Tournament.objects.get(id=self.instance.tournament.id)
        self.queryset = Game.objects.filter(tournament=curr_tournament)
        self.fields['opponent_black'].queryset = curr_tournament.participants
        self.fields['opponent_white'].queryset = curr_tournament.participants
在views.py中

    GameFormSet = formset_factory(GameForm)

之后:

games = Game.objects.filter(tournament=tournament_id).order_by('number_of_game_in_tour', 'number_of_tour')
gameformset = GameFormSet(initial=list(games.values()))

最后,我将gameformset传递给模板并将其呈现为:

<form>
{{ gameformset.management_form }}
{% for gameform in gameformset %}
    {{ gameform }}
{% endfor %}
</form>

这一切都会导致错误:

'auto_id' is an invalid keyword argument for this function

我看不出这种情况发生的原因?也许你呢?

0 个答案:

没有答案