Good, I would appreciate the help, I seem to be blocked with this, and it should not be complicated.
I have a function in views.py that instantiates a form in the following way
form = BusquedaPresenciaForm(initial={'fecha_inicio': datetime.date.today(), 'fecha_fin': datetime.date.today()}, form_kwargs={'usuario_actual': request.user.id})
In forms.py I have the following form
class BusquedaPresenciaForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
usuario_actual = kwargs.pop('usuario_actual')
super(BusquedaPresenciaForm, self).__init__(*args, **kwargs)
self.fields['usuario'].queryset = Coordinacion.objects.filter(coordinador=usuario_actual.id)
It is a question of a filter of the user field of the form filtered by a field in the form, according to the current user.
The error that is returning me is:
Exception Type: KeyError
Exception Value:
'current_user'
On the line: current_user = kwargs.pop ('current_user')