我正在尝试为Django简单历史记录中的history_date字段创建自定义模型,但是当尝试保存到数据库时,出现错误.. autofunction::
我已经在默认NOT NULL constraint failed
模型(例如history_date
)的当前字段中获得了一些数据,但我想将其更改为“天/月/年”
我已使用2019-05-29 19:19:03.922533
文档:https://django-simple-history.readthedocs.io/en/2.7.0/historical_model.html#custom-history-date
型号:
from datetime import datetime
跟踪:
class NodesData(models.Model):
Node = models.CharField(max_length=20, default="Anonymous Node")
NodeIP = models.CharField(max_length=15)
NodeCountry = models.CharField(max_length=30, default="Not Found")
NodeCity = models.CharField(max_length=30, default="Not Found")
NodeISP = models.CharField(max_length=30, default="Not Found")
NodeLat = models.CharField(max_length=15, default="Not Found")
NodeLon = models.CharField(max_length=15, default="Not Found")
Node_id = models.CharField(max_length=128, default="Not Found")
Node_Cores = models.CharField(max_length=15, default="Not Found")
Node_Subtask_Success = models.CharField(max_length=15, default="Not Found")
Node_Subtask_Error = models.CharField(max_length=15, default="Not Found")
Node_Subtask_Timeout = models.CharField(max_length=15, default="Not Found")
Node_Task_Requested = models.CharField(max_length=15, default="Not Found")
Node_Blender_Performance = models.CharField(max_length=15, default="Not Found")
Node_OS = models.CharField(max_length=10, default="Not Found")
Node_OS_system = models.CharField(max_length=10, default="Not Found")
Node_OS_release = models.CharField(max_length=25, default="Not Found")
Node_OS_version = models.CharField(max_length=300, default="Not Found")
Node_OS_windows_edition = models.CharField(max_length=25, default="Not Found", blank=True)
Node_OS_linux_distribution = models.CharField(max_length=50, default="Not Found", blank=True)
Node_Version = models.CharField(max_length=8, default="Not Found")
Node_Memory = models.CharField(max_length=15, default="Not Found")
Node_Disk = models.CharField(max_length=15, default="Not Found")
history = HistoricalRecords()
__history_date = None
@property
def _history_date(self):
return self.__history_date
@_history_date.setter
def _history_date(self, value):
value = datetime.today().strftime('%d-%m-%Y')
self.__history_date = value