G
G
Gleb2021-02-07 17:08:22
Django
Gleb, 2021-02-07 17:08:22

How to solve list indices must be integers or slices, not str?

I get an error list indices must be integers or slices, not str in get_form UpdateView on this line:

self.fields['category'] = Category.objects.all().filter(user=self.request.user)

How to solve it?

Vod code of the class itself:
class HomeUpdateView(UpdateView):
    model = Model
    fields = ['title',  'category']
    success_url = '/account/home'
    template_name = 'main/update/update_home.html'

    def get_form(self, form_class=None):
        self.fields['category'].queryset = Category.objects.all().filter(user=self.request.user)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-02-07
@paundaa

Learn to debug, you have a list in fields, not a dictionary, well, this code

self.fields['category'].queryset = Category.objects.all().filter(user=self.request.user)
for classes from form, not from view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question