my views.py
def upload(request):
if request.user.is_authenticated():
user = User.objects.get(pk=request.user.id)
if request.method == "POST":
form = UploadForm(request.POST, request.FILES,instance=user)
#print form
if form.is_valid():
#m = Upload.objects.all()
#print m
instance=Upload(image=request.FILES['image'])
instance.save()
#m = Upload(image=image)
#print m
#m.save()
#return HttpResponseRedirect(reverse('profile_edit'))
else:
form = UploadForm(instance=user)
return render_to_response('upload.html', { 'form' : form })
return render_to_response("upload.html",{"user":user},context_instance=RequestContext(request))
my models.py
class Upload(models.Model):
user = models.OneToOneField(User)
#email = models.CharField(max_length=120)
#description = models.TextField()
#website = models.CharField(max_length=512)
image = models.ImageField('Label', upload_to='static/media/')
user_id = models.IntegerField()
my forms.py
class UploadForm(ModelForm):
class Meta:
model = Upload
exclude = ("user")
现在的问题是我的views函数中POST得到的data save不到mysql数据库中去 ~~~