ジャンゴチュートリアルパート6アプリでテーブルの中身を好きな順番で並べる
https://docs.djangoproject.com/en/4.0/intro/tutorial03/#write-views-that-actually-do-something

管理でみると Questinons 4まである状態でも

最新の 4から 2まで 3つだけ並んだ.

一番古い、最新から 4つ目の 疑問文まで並んだ.

古い順で並ぶ.

これで区切られる.ビューを気にするのはフロントの仕事になるので、こうやってみやすい区切り文字に変更することはないと思うが.
次回は テンプレート.
ポーリング/テンプレート/インデックス.HTMLを ビューに組み込み、テーブルのデータを HTMLに渡すようにする.
from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:3]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
質問テーブルを モデルからインポート<QuerySet [
<Question: What's new?>, <Question: Question 2>,
<Question: Questions 3>, <Question: Questions 4>
]>
質問の オブジェクトを作成日順に 3つまでに制限して取得する.["What's new?", 'Question 2', 'Questions 3', 'Questions 4']
,
で 先ほどのリストを展開したものを連結する
管理でみると Questinons 4まである状態でも

最新の 4から 2まで 3つだけ並んだ.
latest_question_list = Question.objects.order_by('-pub_date')[:4]
これを 4に変更すると
一番古い、最新から 4つ目の 疑問文まで並んだ.
latest_question_list = Question.objects.order_by('pub_date')[:4]
-pub_date
を pub_date
に変更すると、
古い順で並ぶ.
output = ' | '.join(
[q.question_text for q in latest_question_list]
)
区切りを |
に変更すると
これで区切られる.ビューを気にするのはフロントの仕事になるので、こうやってみやすい区切り文字に変更することはないと思うが.
次回は テンプレート.
ポーリング/テンプレート/インデックス.HTMLを ビューに組み込み、テーブルのデータを HTMLに渡すようにする.
Reference
この問題について(ジャンゴチュートリアルパート6アプリでテーブルの中身を好きな順番で並べる), 我々は、より多くの情報をここで見つけました https://dev.to/kaede_io/django-tutorial-part-6-polls-no-index-de-questiontext-wobing-beru-1logテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol