Skip to content Skip to sidebar Skip to footer

Model Has No Attribute _committed

I'm using jquery form plugin http://jquery.malsup.com/form/#getting-started to upload images through ajax. When I try to upload it shows the model has no attribute _committed Here

Solution 1:

Instead of g.background = form in the else branch, try

try:
    g = BackgroundModel.objects.get(user=request.user)
except BackgroundModel.DoesNotExist:
    data = form.save(commit=False)
    data.user = request.user
    data.save()
else:
    g.background = form.save(commit=False).background
    g.save()
    # or
    BackgroundModelForm(request.POST, request.FILES, instance=g).save()

Only a value of accepted types could be assigned to corresponding field of a model instance.
models.ImageField here accepts

  • file path string
  • django.db.models.fields.files.ImageFieldFile
  • django.core.files.images.ImageFile

Post a Comment for "Model Has No Attribute _committed"