質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -107,3 +107,89 @@
|
|
107
107
|
思いついたものは`exec()`や`eval()`ですがこのようなものは使用したくありません。
|
108
108
|
|
109
109
|
どうにか対処方法を教えてください。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
# 追記(2つめの問題)
|
114
|
+
|
115
|
+
```python
|
116
|
+
|
117
|
+
def post_foreign(foreign, request):
|
118
|
+
|
119
|
+
if (foreign == 'types'):
|
120
|
+
|
121
|
+
Type.create(
|
122
|
+
|
123
|
+
type=request.form['type'],
|
124
|
+
|
125
|
+
created_at=datetime.datetime.now(),
|
126
|
+
|
127
|
+
updated_at=datetime.datetime.now()
|
128
|
+
|
129
|
+
),
|
130
|
+
|
131
|
+
elif (foreign == 'groups'):
|
132
|
+
|
133
|
+
Group.create(
|
134
|
+
|
135
|
+
group=request.form['group'],
|
136
|
+
|
137
|
+
created_at=datetime.datetime.now(),
|
138
|
+
|
139
|
+
updated_at=datetime.datetime.now()
|
140
|
+
|
141
|
+
),
|
142
|
+
|
143
|
+
elif (foreign == 'categories'):
|
144
|
+
|
145
|
+
Category.create(
|
146
|
+
|
147
|
+
category=request.form['category'],
|
148
|
+
|
149
|
+
created_at=datetime.datetime.now(),
|
150
|
+
|
151
|
+
updated_at=datetime.datetime.now()
|
152
|
+
|
153
|
+
),
|
154
|
+
|
155
|
+
elif (foreign == 'formats'):
|
156
|
+
|
157
|
+
Format.create(
|
158
|
+
|
159
|
+
format=request.form['format'],
|
160
|
+
|
161
|
+
created_at=datetime.datetime.now(),
|
162
|
+
|
163
|
+
updated_at=datetime.datetime.now()
|
164
|
+
|
165
|
+
),
|
166
|
+
|
167
|
+
elif (foreign == 'attributes'):
|
168
|
+
|
169
|
+
Attribute.create(
|
170
|
+
|
171
|
+
attribute=request.form['attribute'],
|
172
|
+
|
173
|
+
created_at=datetime.datetime.now(),
|
174
|
+
|
175
|
+
updated_at=datetime.datetime.now()
|
176
|
+
|
177
|
+
),
|
178
|
+
|
179
|
+
else:
|
180
|
+
|
181
|
+
return returnError404()
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
return returnResultCreate()
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
わかりづらく申し訳ありませんでした。
|
192
|
+
|
193
|
+
正確には、上記のように`Type, Group, Category, Format, Attribute`とその中身の一部が違うだけで基本は同じです。
|
194
|
+
|
195
|
+
このコードのメンテナンスコストとタイプ量を減らしたいと考えています。
|