Почему выводит ошибку 'form': AddAvailabilityForm(initial={'name': games}),
TypeError: __init__() missing 1 required positional argument: 'name'
forms.py
class AddAvailabilityForm(forms.ModelForm):
def __init__(self, name, *args, **kwargs):
super(AddAvailabilityForm, self).__init__(*args, **kwargs)
self.fields['name'].queryset = Test.objects.filter(name=name)
class Meta:
model = Test
fields = ['name', 'id_num']
widgets = {
'name': forms.Select(),
'id_num': forms.Select()
}
views.py<code lang="python">
class SellAvailabilityDetail(View):
def get(self, request, slug):
games = Test.objects.get(id_num=slug)
if request.POST:
form = AddAvailabilityForm(request.POST)
if form.is_valid():
form.save()
return redirect('base')
context = {
'form': AddAvailabilityForm(initial={'name': games}), - причем вот здесь скобку подчеркивает желтым
'games': games
}
return render(request, 'Pay/sell_availability_detail.html', context)
</code>