質問編集履歴
7
コードの修正。何度も何度も修正してしまい申し訳ありません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
link_items = list()
|
51
51
|
url_list = ['algorithm.html', 'data.html', 'graph.html', 'search.html', 'sort.html']
|
52
52
|
for url in url_list:
|
53
|
-
for link in link_list: # linklistにはurl
|
53
|
+
for link in link_list: # linklistには外側のループ毎にいくつかのurlがランダムに格納されています。
|
54
54
|
new_link = Link(source=url, target=link)
|
55
55
|
link_items.append(new_link)
|
56
56
|
db.session.add_all(link_items)
|
6
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,10 +48,11 @@
|
|
48
48
|
また、格納は以下のコードで行いました。
|
49
49
|
```ここに言語を入力
|
50
50
|
link_items = list()
|
51
|
-
|
51
|
+
url_list = ['algorithm.html', 'data.html', 'graph.html', 'search.html', 'sort.html']
|
52
|
+
for url in url_list:
|
52
|
-
for link in link_list: # linklistにはurlをランダムに入れています。
|
53
|
+
for link in link_list: # linklistにはurlをランダムに入れています。
|
53
|
-
|
54
|
+
new_link = Link(source=url, target=link)
|
54
|
-
|
55
|
+
link_items.append(new_link)
|
55
56
|
db.session.add_all(link_items)
|
56
57
|
db.session.commit()
|
57
58
|
```
|
5
文章の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
source_list = db.session.query(Link.source).filter_by(target=url).all()
|
9
9
|
```
|
10
10
|
model.pyで定義したLinkクラスの「特定のtargetのsourceだけを抜き取りたい」と考えて上記の処理を記述したのですが、source_listになにも格納されません。
|
11
|
-
|
11
|
+
以下のようにLinkにはデータが格納されています。
|
12
12
|
|
13
13
|
```ここに言語を入力
|
14
14
|
links = Link.query.all()
|
@@ -23,7 +23,7 @@
|
|
23
23
|
↓出力
|
24
24
|
[('algorithm.html',), ('graph.html',), ('search.html',), ('sort.html',)]
|
25
25
|
|
26
|
-
しかし、以下だとできない。
|
26
|
+
しかし、以下だとできないです。
|
27
27
|
|
28
28
|
url_list = ['algorithm.html', 'data.html', 'graph.html', 'search.html', 'sort.html']
|
29
29
|
for url in url_list:
|
4
より情報を加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,20 +8,32 @@
|
|
8
8
|
source_list = db.session.query(Link.source).filter_by(target=url).all()
|
9
9
|
```
|
10
10
|
model.pyで定義したLinkクラスの「特定のtargetのsourceだけを抜き取りたい」と考えて上記の処理を記述したのですが、source_listになにも格納されません。
|
11
|
-
例えば、以下のようにデータが格納されています。
|
11
|
+
例えば、以下のようにLinkにはデータが格納されています。
|
12
12
|
|
13
13
|
```ここに言語を入力
|
14
14
|
links = Link.query.all()
|
15
15
|
↓出力
|
16
16
|
[<Link algorithm.html, data.html>, <Link algorithm.html, search.html>, <Link algorithm.html, sort.html>, <Link data.html, graph.html>, <Link graph.html, data.html>, <Link graph.html, search.html>, <Link search.html, data.html>, <Link search.html, sort.html>, <Link sort.html, data.html>, <Link sort.html, search.html>]
|
17
17
|
```
|
18
|
-
|
18
|
+
例えば、target(右の値)==data.htmlを持っているLinkのsourceだけのリストを作りたいです。
|
19
19
|
|
20
|
-
targetの値
|
20
|
+
targetの値に絞ると以下のように出力されます。
|
21
21
|
```ここに言語を入力
|
22
22
|
links = db.session.query(Link.source).filter_by(target="data.html").all()
|
23
23
|
↓出力
|
24
24
|
[('algorithm.html',), ('graph.html',), ('search.html',), ('sort.html',)]
|
25
|
+
|
26
|
+
しかし、以下だとできない。
|
27
|
+
|
28
|
+
url_list = ['algorithm.html', 'data.html', 'graph.html', 'search.html', 'sort.html']
|
29
|
+
for url in url_list:
|
30
|
+
print(url)
|
31
|
+
print(type(url))
|
32
|
+
source_list = db.session.query(Link.source).filter_by(target= f"{url}").all() # (target=url)もだめでした。
|
33
|
+
↓出力
|
34
|
+
algorithm.html
|
35
|
+
<class 'str'>
|
36
|
+
[]
|
25
37
|
```
|
26
38
|
|
27
39
|
モデルは以下のとおりです。
|
3
足りない情報を加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,14 +11,21 @@
|
|
11
11
|
例えば、以下のようにデータが格納されています。
|
12
12
|
|
13
13
|
```ここに言語を入力
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
links = Link.query.all()
|
15
|
+
↓出力
|
16
|
+
[<Link algorithm.html, data.html>, <Link algorithm.html, search.html>, <Link algorithm.html, sort.html>, <Link data.html, graph.html>, <Link graph.html, data.html>, <Link graph.html, search.html>, <Link search.html, data.html>, <Link search.html, sort.html>, <Link sort.html, data.html>, <Link sort.html, search.html>]
|
17
17
|
```
|
18
|
-
|
18
|
+
条件にtarget(右の値)==data.htmlを持っているLinkのsourceだけのリストを作りたいです。
|
19
19
|
|
20
|
-
|
20
|
+
targetの値を絞ると以下のように出力されます。
|
21
21
|
```ここに言語を入力
|
22
|
+
links = db.session.query(Link.source).filter_by(target="data.html").all()
|
23
|
+
↓出力
|
24
|
+
[('algorithm.html',), ('graph.html',), ('search.html',), ('sort.html',)]
|
25
|
+
```
|
26
|
+
|
27
|
+
モデルは以下のとおりです。
|
28
|
+
```ここに言語を入力
|
22
29
|
#models.py
|
23
30
|
|
24
31
|
class Link(db.Model):
|
@@ -29,8 +36,8 @@
|
|
29
36
|
また、格納は以下のコードで行いました。
|
30
37
|
```ここに言語を入力
|
31
38
|
link_items = list()
|
32
|
-
url = "aaa.html"
|
33
|
-
|
39
|
+
url = ['algorithm.html', 'data.html', 'graph.html', 'search.html', 'sort.html'] # これを一つずつforで回しています。
|
40
|
+
for link in link_list: # linklistにはurlをランダムに入れています。
|
34
41
|
new_link = Link(source=url, target=link)
|
35
42
|
link_items.append(new_link)
|
36
43
|
db.session.add_all(link_items)
|
2
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,6 +29,7 @@
|
|
29
29
|
また、格納は以下のコードで行いました。
|
30
30
|
```ここに言語を入力
|
31
31
|
link_items = list()
|
32
|
+
url = "aaa.html"
|
32
33
|
for link in link_list: # linklistには["ddd.html", "eee.html", "fff.html"]といったように格納されています。
|
33
34
|
new_link = Link(source=url, target=link)
|
34
35
|
link_items.append(new_link)
|
1
より詳細に。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,8 +7,18 @@
|
|
7
7
|
|
8
8
|
source_list = db.session.query(Link.source).filter_by(target=url).all()
|
9
9
|
```
|
10
|
-
model.pyで定義したLinkクラスの「特定のtargetのsourceだけを抜き取りたい」と考えて上記の処理を記述したのですが、source_listになにも格納されません。
|
10
|
+
model.pyで定義したLinkクラスの「特定のtargetのsourceだけを抜き取りたい」と考えて上記の処理を記述したのですが、source_listになにも格納されません。
|
11
|
+
例えば、以下のようにデータが格納されています。
|
12
|
+
|
11
13
|
```ここに言語を入力
|
14
|
+
source → ["aaa.html", "bbb.html", "ccc.html"]
|
15
|
+
↓ ↓ ↓
|
16
|
+
target → ["ddd.html", "eee.html", "fff.html"]
|
17
|
+
```
|
18
|
+
上記のように条件にaaa.htmlと絞り、targetにある値を取得したいです。
|
19
|
+
|
20
|
+
Linkのsourceとtargetにそれぞれ値が入っているのは確認しています。url, source, target はすべてstr型です。
|
21
|
+
```ここに言語を入力
|
12
22
|
#models.py
|
13
23
|
|
14
24
|
class Link(db.Model):
|
@@ -16,4 +26,14 @@
|
|
16
26
|
target = db.Column(db.String(150), primary_key=True)
|
17
27
|
```
|
18
28
|
|
29
|
+
また、格納は以下のコードで行いました。
|
30
|
+
```ここに言語を入力
|
31
|
+
link_items = list()
|
32
|
+
for link in link_list: # linklistには["ddd.html", "eee.html", "fff.html"]といったように格納されています。
|
33
|
+
new_link = Link(source=url, target=link)
|
34
|
+
link_items.append(new_link)
|
35
|
+
db.session.add_all(link_items)
|
36
|
+
db.session.commit()
|
37
|
+
```
|
38
|
+
|
19
39
|
行き詰まっています。何卒ご教授よろしくお願いいたします。
|