0

让我们看看这些模型:

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 上设置相同的默认值并使用原始模型中的相同选项。我怎样才能做到这一点?

4

1 回答 1

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')

寻找一种存储状态更改日期的方法..

于 2013-03-05T19:23:22.560 回答