[Fixed]-How to get current signed user in forms.py?

1👍

Getting the user in __init__() is only the first part of the solution. You also need to use that user to filter the queryset:

class InvoiceCreationForm(forms.Form):
    def __init__(self, *args, **kwargs):
         self.user = kwargs.pop('user', None)
         super(InvoiceCreationForm, self).__init__(*args, **kwargs)
         if self.user:
             self.fields['provider'].queryset = Provider.objects.filter(user=self.user)

Leave a comment