在Foreign Key Django模型上继承或设置选项

时间:2013-03-05 11:47:58

标签: django foreign-keys default models

我们来看看这些模型:

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上原始模型中的相同选项。我怎么能这样做?

1 个答案:

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

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