我尝试使用django orm来更新图像字段,即用户稍后将添加图像并在主表中更新
我试过了
MerchantProfile.objects.filter(id='%s'%(cd['id'])).update(photo='%s'%(cd['photo']))
但它将只更新标题,而不保存在文件夹中的图像
然后我试着跟着
^{pr2}$它将保存图像,但会显示如下错误:payment_card
不能是{
我的模型如下
class Merchantprofile:
user = models.OneToOneField(UserProfile, related_name="merchant_profile")
payment_card = models.OneToOneField(PaymentCard, related_name="merchant_profile")
current_state = models.IntegerField('State', choices=STATE_CHOICES)
name = models.CharField('Merchant Name', max_length=64)
photo=models.ImageField(upload_to='logo',blank=True)
形式
class LogoForm(forms.Form):
id = forms.CharField(widget=forms.HiddenInput,required=False)
photo = forms.ImageField(
required=False,
label='Upload photo',
initial=True,
help_text='max. 4 megabytes'
)
那么什么是最好的方式来更新照片领域只上传照片在相关文件夹,因为我不能更新所有的领域每次
试试这个:
相关问题 更多 >
编程相关推荐