Skip to content

Init form_class #1174

Answered by nikolaik
moas asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this:

from django.contrib.auth.forms import PasswordChangeForm
from graphene_django.forms.mutation import DjangoFormMutation


class MyPasswordChangeForm(PasswordChangeForm):
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super().__init__(user, *args, **kwargs)


class ChangePassword(DjangoFormMutation):
    class Meta:
        form_class = MyPasswordChangeForm

    @classmethod
    def get_form_kwargs(cls, root, info, **mutation_input):
        return {**super().get_form_kwargs(root, info, **mutation_input), 'user': info.context.user}

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #552 on April 14, 2021 20:09.