[Answer]-QuerySet in Django – returns exception

1👍

If using BeneficientPager, you need to do

BeneficientePagar.objects.filter(beneficient__nome__contains="Joao Pedro") 

0👍

You are getting the error because nome is a field on Beneficiente, not BeneficientePagar.

You can either do

Beneficiente.objects.filter(nome__contains="Joao Pedro") 

which will return a queryset of Beneficientes. Or if you need BeneficientePagar you can query through the foreign key.

BeneficientePagar.objects.filter(beneficiente__nome__contains="Joao Pedro")

Leave a comment