Hello, I’m trying to use a modified __init__ form method, but I am encountering the following error:
TypeError
__init__() got multiple values for keyword argument 'vUserProfile'
I need to pass UserProfile to my form, to get to dbname field, and I think this is a solution (my form code):
class ClienteForm(ModelForm):
class Meta:
model = Cliente
def __init__(self, vUserProfile, *args, **kwargs):
super(ClienteForm, self).__init__(*args, **kwargs)
self.fields["idcidade"].queryset = Cidade.objects.using(vUserProfile.dbname).all()
Calls to constructor ClienteForm() without POST are successful and show me the correct form. But when the form is submitted and the constructor is called with POST, I get the previously described error.
You’ve changed the signature of the form’s
__init__method so thatvUserProfileis the first argument. But here:you pass
request.POSTas the first argument – except that this will be interpreted asvUserProfile. And then you also try to passvUserProfileas a keyword arg.Really, you should avoid changing the method signature, and just get the new data from
kwargs: