回答編集履歴
2
修正
test
CHANGED
@@ -31,3 +31,15 @@
|
|
31
31
|
super(MyModel, self).save(*args, **kwargs)
|
32
32
|
|
33
33
|
```とかで、できそうです。
|
34
|
+
|
35
|
+
```Python
|
36
|
+
|
37
|
+
class MyForm(forms.ModelForm):
|
38
|
+
|
39
|
+
class Meta:
|
40
|
+
|
41
|
+
model = MyModel
|
42
|
+
|
43
|
+
fields = ["duration"]
|
44
|
+
|
45
|
+
```
|
1
修正
test
CHANGED
@@ -7,3 +7,27 @@
|
|
7
7
|
duration = models.DurationField()
|
8
8
|
|
9
9
|
```[参考](https://www.366service.com/jp/qa/5a3910187e2b883ced28a4f1c9434e29)
|
10
|
+
|
11
|
+
***
|
12
|
+
|
13
|
+
**追記**
|
14
|
+
|
15
|
+
```Python
|
16
|
+
|
17
|
+
class MyModel(models.Model):
|
18
|
+
|
19
|
+
duration = models.DurationField()
|
20
|
+
|
21
|
+
def save(self, *args, **kwargs):
|
22
|
+
|
23
|
+
m_s = str(self.duration.microseconds).replace("0", "")
|
24
|
+
|
25
|
+
hr = self.duration.seconds / 3600
|
26
|
+
|
27
|
+
if hr != 0 and len(m_s) != 2:
|
28
|
+
|
29
|
+
raise ValueError("有効な値を入力してください。")
|
30
|
+
|
31
|
+
super(MyModel, self).save(*args, **kwargs)
|
32
|
+
|
33
|
+
```とかで、できそうです。
|