1👍
✅
Iterate through all Post objects, and create a new file for each of them.
def deneme(request):
dir_path = Path('/Users/emr/Desktop/ngsaglik/homeo/patient/templates/kayitlar')
kayitlar = Post.objects.all()
for kayit in kayitlar:
file_name = str(kayit.name)
f = open (dir_path.joinpath(file_name),'w')
testfile = File(f)
lines = []
lines.append(f'{kayit.soru1}\n{kayit.soru2}\n')
testfile.write(str(lines))
testfile.close
f.close
return HttpResponse()
Source:stackexchange.com