質問編集履歴
2
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Django model
|
1
|
+
Django modelを継承してカラムの内容で分けた別のmodelを作成する方法
|
test
CHANGED
File without changes
|
1
標題、本文が分かりにくかったので訂正しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
modelの
|
1
|
+
Django modelのカラムを継承してカラムの内容で分ける別のmodelを作成
|
test
CHANGED
@@ -1,16 +1,36 @@
|
|
1
|
-
|
1
|
+
appを2つ作り、Aのmodelで登録した内容を継承したmodelを3つ作りたいと考えています。
|
2
|
+
|
3
|
+
1つ目のappは製品を登録する台帳機能を持ったAのmodel。 ※作成済み
|
4
|
+
|
5
|
+
2つ目のappはAの台帳で登録した内容を引用(継承)した点検チェックシートを作成するためのBとCのmodel。
|
2
6
|
|
3
7
|
|
4
8
|
|
9
|
+
詳細と困り事は以下。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
詳細:
|
14
|
+
|
5
|
-
|
15
|
+
A、台帳登録用:品に対しての情報が登録されて、多数の品が無限に登録されていく。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
B、line毎に振り分ける:台帳登録用のmodel class.InsLedgerで登録したカラムの内容を継承してline登録が同じもの同士に分ける。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
困り事1⇒line毎にclassを作成する?継承元が際限なく無数に増えていく場合の分け方がわかりません。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
C、Bで分けたline毎の情報を読み取り専用(更新不可)で項目にして点検チェックシート用のmodelを作成する。
|
28
|
+
|
29
|
+
困り事2⇒ここも複数のclassを作成する必要がありますか?
|
6
30
|
|
7
31
|
|
8
32
|
|
9
33
|
|
10
|
-
|
11
|
-
この手順で作成する予定ですが、簡単な手順や、ご指摘があればご教授いただきたいです。
|
12
|
-
|
13
|
-
具体的には台帳modelから日常点検記録用modelに直接登録内容を継承できる方法はないか。
|
14
34
|
|
15
35
|
|
16
36
|
|
@@ -30,7 +50,7 @@
|
|
30
50
|
|
31
51
|
|
32
52
|
|
33
|
-
|
53
|
+
Aの台帳model↓
|
34
54
|
|
35
55
|
|
36
56
|
|
@@ -46,7 +66,7 @@
|
|
46
66
|
|
47
67
|
ins_num = models.CharField(max_length=10)
|
48
68
|
|
49
|
-
calibration_type = models.IntegerField(choices=CALIBRATION_CHOICES)
|
69
|
+
calibration_type = models.IntegerField(choices=CALIBRATION_CHOICES)
|
50
70
|
|
51
71
|
calibration_date = models.DateField(default=now)#datetime.datetime.now())
|
52
72
|
|
@@ -54,53 +74,81 @@
|
|
54
74
|
|
55
75
|
serial_num = models.CharField(max_length=20, null=True, blank=True, default='')
|
56
76
|
|
57
|
-
product_num = models.ForeignKey(Product_num, on_delete=models.CASCADE)
|
77
|
+
product_num = models.ForeignKey(Product_num, on_delete=models.CASCADE)
|
58
78
|
|
59
|
-
team = models.ForeignKey(TeamModel, on_delete=models.CASCADE, related_name='teams1')
|
79
|
+
# team = models.ForeignKey(TeamModel, on_delete=models.CASCADE, related_name='teams1')
|
60
80
|
|
61
81
|
line = models.ForeignKey(LineModel, on_delete=models.CASCADE, related_name='lines1')
|
62
82
|
|
63
|
-
useapp = models.ForeignKey(Useapp, on_delete=models.CASCADE)
|
83
|
+
useapp = models.ForeignKey(Useapp, on_delete=models.CASCADE)
|
64
84
|
|
65
|
-
spec1 = models.ForeignKey(Spec1, on_delete=models.CASCADE)
|
85
|
+
spec1 = models.ForeignKey(Spec1, on_delete=models.CASCADE)
|
66
86
|
|
67
|
-
spec2 = models.ForeignKey(Spec2, on_delete=models.CASCADE)
|
87
|
+
spec2 = models.ForeignKey(Spec2, on_delete=models.CASCADE)
|
68
88
|
|
69
|
-
spec3 = models.IntegerField(choices=SPEC3_CHOICES)
|
89
|
+
spec3 = models.IntegerField(choices=SPEC3_CHOICES)
|
70
90
|
|
71
|
-
check_items = models.ForeignKey(Check_Items, on_delete=models.CASCADE)
|
91
|
+
check_items = models.ForeignKey(Check_Items, on_delete=models.CASCADE)
|
92
|
+
|
93
|
+
ins_result = models.CharField(max_length=10,)
|
72
94
|
|
73
95
|
|
74
96
|
|
75
97
|
def save(self, *args, **kwargs):
|
76
98
|
|
77
|
-
auto_now = kwargs.pop('next_calibration_date_auto_now', True)
|
99
|
+
auto_now = kwargs.pop('next_calibration_date_auto_now', True)
|
78
100
|
|
79
|
-
if auto_now:
|
101
|
+
if auto_now:
|
80
102
|
|
81
|
-
if self.calibration_type == CALIBRATION_CHOICES[0][0]:
|
103
|
+
if self.calibration_type == CALIBRATION_CHOICES[0][0]:
|
82
104
|
|
83
|
-
calibration_span = 1
|
105
|
+
calibration_span = 1
|
84
106
|
|
85
|
-
elif self.calibration_type == CALIBRATION_CHOICES[1][0]:
|
107
|
+
elif self.calibration_type == CALIBRATION_CHOICES[1][0]:
|
86
108
|
|
87
|
-
calibration_span = 2
|
109
|
+
calibration_span = 2
|
88
110
|
|
89
|
-
elif self.calibration_type == CALIBRATION_CHOICES[2][0]:
|
111
|
+
elif self.calibration_type == CALIBRATION_CHOICES[2][0]:
|
90
112
|
|
91
|
-
calibration_span = 5
|
113
|
+
calibration_span = 5
|
92
114
|
|
93
|
-
elif self.calibration_type == CALIBRATION_CHOICES[3][0]:
|
115
|
+
elif self.calibration_type == CALIBRATION_CHOICES[3][0]:
|
94
116
|
|
95
|
-
calibration_span = 10
|
117
|
+
calibration_span = 10
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
self.next_calibration_date = self.calibration_date + relativedelta(years=calibration_span)
|
100
118
|
|
101
119
|
|
102
120
|
|
121
|
+
self.next_calibration_date = self.calibration_date + relativedelta(years=calibration_span)
|
122
|
+
|
123
|
+
self.passorfail()
|
124
|
+
|
103
|
-
super().save(*args, **kwargs)
|
125
|
+
super().save(*args, **kwargs)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
def passorfail(self):
|
132
|
+
|
133
|
+
today = datetime.today()
|
134
|
+
|
135
|
+
if self.next_calibration_date.strftime('%Y-%m-%d') == today.strftime('%Y-%m-%d'):
|
136
|
+
|
137
|
+
pass_result = ('対象')
|
138
|
+
|
139
|
+
elif self.next_calibration_date.strftime('%Y-%m-%d') > today.strftime('%Y-%m-%d'):
|
140
|
+
|
141
|
+
pass_result = ('合格')
|
142
|
+
|
143
|
+
else:
|
144
|
+
|
145
|
+
pass_result = ('不合格')
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
self.ins_result = pass_result
|
150
|
+
|
151
|
+
|
104
152
|
|
105
153
|
|
106
154
|
|
@@ -112,6 +160,6 @@
|
|
112
160
|
|
113
161
|
class Meta:
|
114
162
|
|
115
|
-
verbose_name = "
|
163
|
+
verbose_name = "台帳"
|
116
164
|
|
117
165
|
```
|