I’m trying to make a simple image upload form, which works until I try to save the Model called User_Image using the posted data. The error I get is this: int() argument must be a string or a number, not ‘QueryDict’ and I receive it at the line marked *****. Thanks for the help.
models.py:
class User_Image(models.Model):
image = models.ImageField(upload_to="img")
user_profile = models.ForeignKey(UserProfile)
title = models.CharField(max_length=10)
forms.py:
class User_ImageForm(ModelForm):
class Meta:
model = User_Image
views.py:
def upload_image(request):
if request.method == 'POST':
HttpResponseRedirect("/accounts/profile")
form = User_ImageForm(request.POST, request.FILES)
if form.is_valid():
im = User_Image(request.POST, request.FILES)
******im = im.save()
HttpResponseRedirect("/accounts/profile")
else:
form = User_ImageForm()
return render_to_response('uploadimage.html', {'form':form}, context_instance=RequestContext(request))
Why are you saving it to the model class directly? Try: