回答編集履歴

1

修正

2020/06/20 20:23

投稿

ForestSeo
ForestSeo

スコア2722

test CHANGED
@@ -12,12 +12,18 @@
12
12
 
13
13
  date = models.DateTimeField('日付', auto_now=True)
14
14
 
15
- nextdate = models.DateTimeField(default=timezone.now())
15
+ nextdate = models.DateTimeField(required=False)
16
16
 
17
17
  def save(self, *args, **kwargs):
18
18
 
19
+ if self.date is None:
20
+
21
+ self.nextdate = timezone.now() + datetime.timedelta(weeks=1)
22
+
23
+ else:
24
+
19
- self.nextdate = self.date + datetime.timedelta(weeks=1)
25
+ self.nextdate = self.date + datetime.timedelta(weeks=1)
20
26
 
21
27
  super().save(*args, **kwargs)
22
28
 
23
- ```保存すると`nextdate`が`date`の一週間後に
29
+ ```