Please guide me if i misunderstand the correct use of defer() or only() in queryset.
This is the code where i am trying to get only seleted fields data from Donor model to make process fast because it has 2000 entries and when i use all() it takes time to fetch data.
def donor(request):
# donors = Donors.objects.all()
donors = Donors.objects.only('donorid','donor_type','title','donor_name','address',
'mobile_no','jamatkhana')
# donors = Donors.objects.defer('donorid','donor_type','title','donor_name','address',
'mobile_no','jamatkhana')
return render(request,"hod_template/add_donor_template.html",{"donors":donors})
After use of "only()" or "defer()" the result is still same as "all()" none of the selected field neither deferred nor only. even it takes more time to load than all().
Please tell me how to get only these selected field data from donor model. i also tell you i tried "Values()" Method as well but the problem is the "jamatkhana" field is ForeignKey and i want its data as well. but using of "Values()" method it only get values not foreignkey inner data. hope i explain properly?