我把我的imagefield设置为NONE,但是当我试图从django管理面板输入没有图像的数据时,它显示这个字段是必需的。
这是我的urls.py
class dish(models.Model):
dish_id = models.AutoField
dish_name = models.CharField(max_length=255)
dish_size = models.CharField(max_length=7)
dish_price = models.IntegerField()
dish_description = models.CharField(max_length=255)
dish_image = models.ImageField(upload_to="", default=None)
dish_date = models.DateField()
def __str__(self):
return self.dish_name
'如果用户没有选择任何图像,如何将其设置为无
1条答案
按热度按时间6rqinv9w1#
Both
blank=True
andnull=True
are needed. Here’s why: What is the difference between null=True and blank=True in Django?——-
Also, you don’t need
dish_id
. IDs are automatically generated and accessed withmodel_instance.pk
https://docs.djangoproject.com/en/4.1/topics/db/models/#automatic-primary-key-fields