def upload(request, customer_id): customer = get_object_or_404(Customer, pk=customer_id) if request.method == 'POST' and request.POST['content']: myfile = request.FILES['myfile'] post = Post() post.content = request.POST['content'] post.createtime = timezone.now() post.updatetime = timezone.now() post.customer = Customer.objects.get(id=customer_id) fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) # image = Image() post.save() for file in request.FILES.getlist('myfile'): image = Image() post.save() image.imageurl = file image.post = Post.objects.get(id=post.id) image.save() # image.imageurl = filename # image.post = Post.objects.get(id=post.id) # post.save() # image.save() return redirect('/customers/' + 'detail/' + str(customer_id)) return render(request, 'customers/detail.html', {'customer': customer})