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