Answer the question
In order to leave comments, you need to log in
Why does 'form': AddAvailabilityForm(initial={'name': games}), TypeError: __init__() missing 1 required positional argument: 'name' error?
Why does '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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question