Django ImageField overwrites existing path when empty
So, that's the problem: I currently have a model:
class UserData(models.Model): avatar = models.ImageField(verbose_name='Avatar',upload_to='images/profile_pics',blank=True,null=True) doc_type = models.CharField(verbose_name='Document type',max_length=1,default='0')
And a form:
class UserCreationForm(forms.ModelForm): avatar = forms.ImageField(label='Avatar',required=False, error_messages = {'invalid':"Images only"}, widget=forms.FileInput) class Meta: model = UserData
So, the problem occurs when the user tries to edit his data. When no image is provided, the current image path in the db overwrites with the empty string. Is there any way to solve that problem?
链接地址: http://www.djcxy.com/p/38682.html上一篇: 如何揭示模型的某些特定领域