我有两个班级:
class Works(models.Model):
name=models.CharField(max_length=255)
time=models.IntegerField()
unit= models.ForeignKey(Units)
price=models.IntegerField()
approve_need=models.BooleanField()
person_value= models.IntegerField()
profession= models.ForeignKey(Professions)
def __unicode__(self):
return self.name
class ProjectsWorks(models.Model):
project_name= models.ForeignKey(Projects)
work_name= models.ForeignKey(Works)
work_amount= models.IntegerField()
complet_per= models.IntegerField()
planned_start= models.DateField()
planned_end= models.DateField()
fact_start= models.DateField()
fact_end= models.DateField()
start_reason= models.CharField(max_length=255)
end_reason= models.CharField(max_length=255)
他们都使用formset在屏幕上显示。将数据添加到Works模型后,我可以以某种方式执行此操作: 选择
之后work_name= models.ForeignKey(Works)
在formset中,字段
ProjectWorks.work_amount
等于
的值Works.time
或者我可以以某种方式在特定对象上使用ForeignKey? 喜欢
class ProjectsWorks(models.Model):
work_amount= models.ForeignKey(Works.time)