我们来看看这些模型:
from .choices import STATUS_CHOISES
class Status(models.Model):
current_status = models.CharField("Current status", max_length=50, choices=STATUS_CHOICES, default='new')
status_change_date = models.DateField(verbose_name="Status change date", default=datetime.datetime.now())
class ProductRequest(models.Model):
destination = models.CharField("Product Destination", max_length=255)
status = models.ForeignKey(Status)
选择:
STATUS_CHOICES = (
('new', 'New'),
('ongoing', 'Ongoing'),
('finalized', 'Finalized'),
)
我需要设置相同的默认值,并使用ForeignKey上原始模型中的相同选项。我怎么能这样做?
答案 0 :(得分:0)
决定转到简单的属性:
class ProductRequest(models.Model):
destination = models.CharField("Product Destination", max_length=255)
status = models.CharField("Request Status", max_length=50, choices=STATUS_CHOICES, default='new')
寻找存储状态更改日期的方法..