質問編集履歴

1

実際のDBイメージの追加

2022/11/28 02:50

投稿

MagMag
MagMag

スコア80

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,33 @@
81
81
  table_name = current_app.config['table_name']
82
82
  ```
83
83
 
84
+ ### 実際のDBファイルのイメージ
85
+ 実際のDBは以下のようになっています。
86
+
87
+ #### DB
88
+ ```Python
89
+ from pynamodb.models import Model
90
+ from pynamodb.attributes import UnicodeAttribute
91
+
92
+ class DB(Model):
93
+ class Meta:
94
+ table_name = application.config.get('TABLE_NAME')
95
+ region = application.config.get('AWS_REGION')
96
+ aws_access_key_id = application.config.get('AWS_ACCESS_KEY_ID')
97
+ aws_secret_access_key = application.config.get('AWS_SECRET_ACCESS_KEY')
98
+
99
+ partition_key = UnicodeAttribute(hash_key=True, null=False)
100
+ ```
101
+
102
+ #### View
103
+ ```Python
104
+ from sub import DB
105
+
106
+ @application.route('/', methods=['GET'])
107
+ def top_page():
108
+ entries = DB_Training.scan()
109
+ entries = sorted(entries, key=lambda x: x.partition_key, reverse=True)
110
+ return render_template('entries/top_page.html', registration_data=entries)
111
+
112
+ ```
113
+