G
G
Gleb2021-02-05 16:44:04
Django
Gleb, 2021-02-05 16:44:04

How to pass request.user to UpdateView?

How to pass request.user to the form that has this code:

def __init__(self, user, *args, **kwargs):
        super(Form, self).__init__(*args, **kwargs)
        self.fields['category'].queryset = Category.objects.all().filter(user=user)

Here is views.py:
class UpdateView(UpdateView):
    model = Model
    success_url = '/account/model'
    template_name = 'main/model.html'

    form_class = Form

Answer the question

In order to leave comments, you need to log in

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

Override method , request will be in self.request. What to override there, you need to look in the source code, it’s not a fact that it will be clear from the docks https://docs.djangoproject.com/en/3.1/ref/class-ba...def get_form(self, form_class=None):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question