I need in forms.py get the user who makes the request to the form. Then using that user instance, get the records associated with it. I created a form with a field ModelChoiceField and in argument queryset trying to get records associated with a user.
my forms.py: class TransfersForm(forms.Form): def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(TransfersForm, self).__init__(*args, **kwargs) account_1 = forms.ModelChoiceField(queryset=Bank_Account.objects.filter(client=self.user)) account_2 = forms.ModelChoiceField(queryset=Bank_Account.objects.filter(client=self.user)) amount = forms.IntegerField() my views.py: def transfers (request): if request.method == 'POST': form = TransfersForm(request.POST, user = request.user) else: form = TransfersForm(user = request.user) return render (request, 'bank/transfers.html', {'menu': menu, 'form': form, 'title': ' transfers'}) But, Django gives an error that self in field account_1 not defined. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e8071adb-f0d0-4978-8539-687cb6bdfda7n%40googlegroups.com.