V
V
Vitaly Ananiev2022-01-08 20:29:57
Django
Vitaly Ananiev, 2022-01-08 20:29:57

Why AttributeError: 'QueryDict' object has no attribute 'all'?

forms.py

class AddAvailabilityForm(forms.Form):
    def __init__(self, server, *args, **kwargs):
        super(AddAvailabilityForm, self).__init__(*args, **kwargs)
        self.fields['server'].queryset = server

    server = forms.ModelChoiceField(queryset=Servers.objects.all(), empty_label=None, label=False)
    availability = forms.IntegerField(label=False, widget=forms.TextInput(attrs={'class': 'form-input'}))
    price = forms.IntegerField(label=False, widget=forms.TextInput(attrs={'class': 'form-input'}))

views.py
def addAvailability(request, slug):
    games = Games.objects.get(id_num=slug)
    server = Servers.objects.filter(id_num=slug)
    if request.method == 'POST':
        form = AddAvailabilityForm(request.POST)
        if form.is_valid():
            Availability.objects.create(**form.cleaned_data)
        return redirect('base')
    else:
        form = AddAvailabilityForm(server)
    context = {
        'form': form,
        'games': games
    }
    return render(request, 'Pay/sell_availability_detail.html', context)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question