Victor Gau
Just Do It!
Skip to content
Home
創業相關
讀書心得
投資相關
Python
Javascript
R
養生保健
←
[Python] Django: 怎麼搜尋指定期間內的物件?
[wordpress] WordPress 更新失敗,結果網站開不起來!?
→
[Python] Django: 怎麼使用變數讀取 Model 的欄位?
Posted on
May 8, 2016
by
Victor
# 讀取欄位值 getattr(model, fieldtoget) # 設定欄位值 setattr(model, fieldtoget, value) # 設定完後要 model.save()
1
2
3
4
5
6
# 讀取欄位值
getattr
(
model
,
fieldtoget
)
# 設定欄位值
setattr
(
model
,
fieldtoget
,
value
)
# 設定完後要 model.save()
參考資料:
Django model field by variable
Share this:
Facebook
Twitter
Google
Like this:
Like
Loading...
Related
This entry was posted in
Python
,
程式設計
and tagged
Python
,
程式設計
. Bookmark the
permalink
.
←
[Python] Django: 怎麼搜尋指定期間內的物件?
[wordpress] WordPress 更新失敗,結果網站開不起來!?
→
Leave a Reply
Cancel reply
Search for:
About Me
高雄人!
目前興趣:
量化投資、物聯網、工業 4.0
主要語言: Python
主要社群:
Kaohsiung Python User Group
April 2018
M
T
W
T
F
S
S
« Mar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Recent Posts:
[讀書心得] 一生做對一次投資:散戶也能賺大錢
[Python] Python 的例外處理 – 02
[Python] Python 的例外處理 – 01
[Python] Python 的檔案IO-文字檔
[Python] Python 的函式
%d
bloggers like this: