Unable to transfer source data to form set

In my Django application, I have the following:

the form:

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

in views.py:

    GameFormSet = formset_factory(GameForm)

later:

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

Finally, I pass gameformsetto the template and do this:

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

All this leads to an error:

'auto_id' is an invalid keyword argument for this function

I see no reason why this could happen? Maybe you do?

+4
source share

Source: https://habr.com/ru/post/1532900/


All Articles