我正在将产品目录从<?php
$date = date("08:00");
for($i=1; $i<=10; $i++)
{
$date = strtotime("+".$i." hour");
echo date('H:i A', $date);
}
?>
文件上传到以下数据库模型中
的 models.py
csv
views.py
class Product(models.Model):
name = models.CharField(max_length=50)
invoice_date = models.DateField(blank=True, null=True)
以下是示例 csv文件数据
def load_product(relative_path):
if relative_path is not None:
with open(os.path.join(BASE_DIR, relative_path)) as f:
reader = csv.reader(f)
for row in reader:
if row[0] != 'id':
_, created = Product.objects.get_or_create(
name=row[1],
invoice_date=datetime.datetime.strptime(str(row[2]), "%d-%m-%Y").strftime("%Y-%m-%d")
)
else:
return "Please enter a relative file name from data folder."
我的一些书id,name,invoice_date
,sample book1,26-10-2007
,sample book2,15-10-2010
,sample book3,22-09-2017,
,sample book4,,
,sample book5,,
所以我想插入无类型(或空),这就是为什么我在don't have invoice_date
中创建blank=True, null=True
,但它没有插入null当我使用shell执行方法时,给出了以下错误
的错误
models.py