【发布时间】:2020-03-16 22:07:29
【问题描述】:
我是编程新手,所以如果我问一些愚蠢的问题,请多多包涵。 我正在做我的第一个项目,该项目将从 Excel 文件中收集数据。我正在为此目的尝试 django-import-export,但遇到了包含日期字段的问题。据我所知,搜索这个问题我需要使用 Date 小部件,因为它在导入时基本上将其读取为字符串。但是我找不到任何使用这个小部件的例子,所以我可以看到它的语法。我正在研究的模型如下所示。希望你们中的一些人能在这方面帮助我。谢谢。
from django.db import models
from import_export.admin import ImportExportModelAdmin
from import_export import widgets
class Employee(models.Model):
name = models.CharField(max_length=200)
badge = models.CharField(max_length=15)
start_date = models.DateField(auto_now=False, auto_now_add=False, blank=False, null=True,widget=widgets.DateWidget(format=None))
end_date = models.DateField(auto_now=False, auto_now_add=False, blank=True, null=True)
status = models.BooleanField(choices=(
(True, 'Active'),
(False, 'Inactive')
), default=True)
job = models.ForeignKey(Matrix, on_delete=models.CASCADE, blank=True, null=True)
location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True, null=True)
def __str__(self):
return str(self.badge)+ str(" - ") + str(self.name)
class Meta:
ordering=('name', 'badge', 'start_date', 'status',)
verbose_name='Employee'
verbose_name_plural='Employees'
【问题讨论】:
标签: python django widget django-import-export