How To Show Dynamic Drop Down In Django?

I want to show the Bank account number of an employee based on his saved banking details while adding salary. But now I am getting all employee's bank account number rather than just selected one. below is my

I tried to set the field in but I do not know how to filter using employee id in that.

class SalaryCreateForm(forms.ModelForm):
        class Meta:
            model = Salary_Rotation
            fields = ('Sal_Emp_Desig', 'Payment_Mode_of_Salary', 'Emp_Acc_number', 'Cheque_Number', 'Transaction_Number', 'P_Tax', 'Salary_Amount', 'Salary_Date')

    def __init__(self, *args, **kwargs):
        super(SalaryCreateForm,self).__init__(*args, **kwargs)
        self.fields['Sal_Emp_Desig'].queryset = Designation.objects.filter(Is_Del=0)
        self.fields['Emp_Acc_number'].queryset = Employee_Bank_Detail.objects.filter(Is_Del=0)

below is my template

<form class="form-group" method="POST">
                                        {% csrf_token %}
                                        <label class="control-label"> Employee Name:- </label>
                                        <input class="form-control" value="{{emp.Emp_Name}}" type="text" name="compnay" readonly/ >
                                        <label class="control-label"> Company Name:- </label>
                                        <input class="form-control" value="{{emp.Emp_company}}" type="text" name="compnay" readonly/ >

                                             <label>Bank Account</label>
                                            <select id="id_Emp_Acc_number" name="Emp_Acc_number" class="form-control" >
                                                    <option value="" selected="">---------</option>

                                            {% for acc_num in bank_acc_numbers %}
                                            <option value="{{}}" >{{ acc_num.Emp_Acc_num }}</option>
                                            {% endfor %}

                                        {{ form|crispy }}
                                        <button class="btn btn-rounded btn-success" type="submit">Add Experience</button>

                            {% for emp in employees%}
                                    <a target="_blank" rel="nofollow noreferrer" href="{% url 'employee-detail' %}" class="btn btn-rounded btn-brand ml-4">Cancel</a>

below is my

class SalaryCraeteView(LoginRequiredMixin,SuccessMessageMixin,CreateView):
    #permission_required = 'Company.add_company'
    success_message = " Salary added successfully!"
    login_url= "login"
    template_name = 'employee_salary_form.html'
    form_class = SalaryCreateForm
    def form_valid(self,form,**kwargs):
        form.instance.Sal_Crt_By = self.request.user
        form.instance.Is_Del =0

def get_context_data(self, **kwargs):
    kwargs['employees'] = Employee.objects.filter(pk=self.kwargs['pk'])
    kwargs['bank_acc_numbers'] = Employee_Bank_Detail.objects.filter(Emp_Bank_id=self.kwargs['pk']).filter(Is_Del=0)

    return super(SalaryCraeteView, self).get_context_data(**kwargs)

I want to show values in drop down based on employee's banking details, not all employee's banking details.



You may send the used_id from the view to the form using the method get_form_kwargs(), like

class SalaryCreateView(...):
    def get_form_kwargs(self):
        kwargs = super(SalaryCreateView, self).get_form_kwargs()
        kwargs['user_id'] =
        return kwargs

and apply this user_id in the filter, like

class SalaryCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.fields['Emp_Acc_number'].queryset = Employee_Bank_Detail.objects.filter(Is_Del=0, <user_id_field>=self.user_id)