Upload images in Django save onlyto folder but not saving to mysql database
I need help my code below save image to folder but not saving to mysql database. pls i dont knw where am getting it wrong.
VIEW.PY
def indeximg(request):
if request.method == "POST":
form=ImageForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('uploadok')
else:
form = ImageForm()
return render(request, 'indeximg.html', {'form': form})
def uploadok(request):
return HttpResponse(' upload successful')
IN MODEL.PY
class Image(models.Model):
caption=models.CharField(max_length=100)
image=models.ImageField(upload_to='images/')
From django docs about ImageFied
ImageFieldinstances are created in your database asvarcharcolumns with a default max length of 100 characters. As with other fields, you can change the maximum length using themax_lengthargument.