0
我设计了两个模型:一个用于存储坐姿日期的模型和另一个用于存储移动日期的模型。两个模型通过外键链接。这里是我的两个型号:移位日期未更新为坐标日期
class Sitting(models.Model):
sit_date = models.DateField(blank=False,unique=True)
cut_off_date = models.DateField(null=True, blank=True)
ballot_date = models.DateField(null=True, blank=True)
sess_no = models.ForeignKey(Session,
on_delete=models.CASCADE)
genre = TreeForeignKey('Genre', null=True, blank=True, db_index=True)
转型模式:
class Shiftdate(models.Model):
shift_date = models.DateField(blank=False,unique=True)
sit_date = models.ForeignKey(Sitting,
on_delete=models.CASCADE)
使用变速模型我改变现有坐日期与其他日期为:
Sitting Date Shifting Date
2016-09-01 Sept. 15, 2016
2016-09-08 Sept. 19, 2016
现在,我想使换挡日期到一个新的开会日期。为此,我定义坐式模型中的以下方法:
def get_shift_date(self):
return self.sit_date.shift_date
并将此shift_date保存在坐标模型中。我定义了以下保存方法:
def save(self, *args, **kwargs):
self.sit_date = self.get_shift_date()
super(Sitting, self).save(*args, **kwargs)
但是,这并不返回换班日期作为坐的日期。有人可以帮我解决这个问题吗?
因此,我改变get_shift_date()为: – ohid
因此,我改变get_shift_date()为: 高清get_shift_date(个体经营): 回报self.sit_date.shift_date 和保存方法 高清保存(个体经营,* ARGS,** kwargs): self.sit_date = self.get_shift_date() super(Sitting,self).save(* args,** kwargs) 但是仍然不起作用 – ohid
您能详细说明您的答案,以便我可以行得通解决方案 – ohid