I am trying to access an authenticated user in a form class. I played with passing the request object from the view to the init class, but it seemed messy. Is there a better way to access an authenticated user or request an object outside of the view?
class LicenseForm(forms.Form):
'''def __init__(self, *args, **kwargs):
#self.fields['license'] = forms.ModelChoiceField(queryset=self.license_queryset(), empty_label='None', widget=forms.RadioSelect())'''
def license_queryset():
queryset = License.objects.filter(organization__isnull=True)
return queryset
licenses = forms.ModelChoiceField(queryset=license_queryset(), empty_label='None', widget=forms.RadioSelect())
source
share