我使用Django框架构建一个简单的库存管理系统。使用django admin填充数据库中的数据。现在,当我在网站上显示数据(前端)时,有一个显示日期的时间字段,虽然我开始学习django,但我认为我的模型是错误的。下面我附上了我的models.py以及实际网站上的错误。
Models.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import time
from django.db import models
class Cart(models.Model):
def __str__(self):
return self.CartColor
CartColor = models.CharField(max_length=255)
Quantity = models.CharField(max_length=5)
class Initials(models.Model):
def __unicode__(self):
return self.Staff
Staff = models.CharField(max_length=255)
FirstName = models.CharField(max_length=255)
LastName = models.CharField(max_length=255)
class RTInfo(models.Model):
def __str__(self):
return str(self.TicketNo)
TicketNo = models.CharField(max_length=10)
# TickStamp = models.DateField(auto_now_add=True, blank=True)
class Room(models.Model):
def __unicode__(self):
return self.Number
Number = models.CharField(max_length=5)
class TCCheckOut(models.Model):
def __str__(self):
return str(self.ReturnDate)
ReturnDate = models.DateField(auto_now_add=True, blank=True)
ReturnTime = models.TimeField(auto_now_add=True, blank=True, unique_for_date=True)
OutQuantity = models.CharField(max_length=255)
Staff = models.ForeignKey(Initials, on_delete=models.CASCADE)
Number = models.ForeignKey(Room, on_delete=models.CASCADE)
CartColor = models.ForeignKey(Cart, on_delete=models.CASCADE)
TicketNo = models.ForeignKey(RTInfo, related_name="custom_user1_profile", on_delete=models.CASCADE)
# TickStamp = models.ForeignKey(RTInfo,related_name="custom_pass2_profile", on_delete=models.CASCADE)
class TCCheckIn(models.Model):
def __str__(self):
return str(self.Date)
Date = models.DateField(auto_now_add=True, blank=True)
Time = models.TimeField(auto_now_add=True, blank=True)
Quantity = models.CharField(max_length=255)
Staff = models.ForeignKey(Initials, on_delete=models.CASCADE)
Number = models.ForeignKey(Room, on_delete=models.CASCADE)
CartColor = models.ForeignKey(Cart, on_delete=models.CASCADE)
TicketNo = models.ForeignKey(RTInfo, related_name="custom_user_profile", on_delete=models.CASCADE)
ReturnDate = models.ForeignKey(TCCheckOut, related_name="value1", on_delete=models.CASCADE)
ReturnTime = models.ForeignKey(TCCheckOut, related_name="timeRet", on_delete=models.CASCADE)
OutQuantity = models.ForeignKey(TCCheckOut, related_name="value3", on_delete=models.CASCADE)
实际错误 Actual_error
从上图中可以看出,即使保存时间,也会显示日期。还有人指出,在Django管理员中,所述时间字段也显示日期,图片已附在下面
我认为,在Django admin中,Return Time应该是一个时间戳,那为什么显示日期?
感谢任何可以提供帮助的人!