0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django .objects.values でリスト連結方法がわからない(Python)。→解決

Last updated at Posted at 2019-10-18

リストの連結方法がわかりません。どなた様かご教授よろしくおねがいします。

view.py
class フォームView(TemplateView):
    data = 試験.objects.values('顧客__姓','顧客__名')
    print(data)
# <QuerySet [
#             {'顧客__姓': '山田', '顧客__名': '一郎'},
#        {'顧客__姓': '安田', '顧客__名': '庄司'},
#        {'顧客__姓': '田中', '顧客__名': '太郎'}
#             ]>
#例のように「顧客__姓」と「顧客__名」を「氏名」のように結合したい。
#(例)
#   <QuerySet [
#              {'氏名':'山田一郎','顧客__姓': '山田', '顧客__名': '一郎'},
#              {'氏名':'安田庄司','顧客__姓': '安田', '顧客__名': '庄司'},
#              {'氏名':'田中太郎','顧客__姓': '田中', '顧客__名': '太郎'}
#              ]>


0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?