###前提・実現したいこと
djangoでアプリを作っています。
下にあるコードから、viewで見れるMoldelclassを作りたいです。
###ソースコード
python
1 2# -*- coding: utf-8 -*- 3from django.db import models 4from googleapiclient.discovery import build 5 6# Create your models here. 7 8 9class SearchYoutube(): 10 args = { 11 "q": "スプラトゥーン", 12 "part": "id,snippet", 13 "maxResults": 50 14 } 15 16 YOUTUBE_API_ACCESS_KEY = '*******************************' 17 __YOUTUBE_API_SERVICE_NAME = "youtube" 18 __YOUTUBE_API_VERSION = "v3" 19 20 def search(self, options): 21 youtube = build( 22 self.__YOUTUBE_API_SERVICE_NAME, 23 self.__YOUTUBE_API_VERSION, 24 developerKey=self.YOUTUBE_API_ACCESS_KEY 25 ) 26 27 # Call the search.list method to retrieve results matching the specified 28 # query term. 29 search_response = youtube.search().list( 30 q=options["q"], 31 part=options["part"], 32 maxResults=options["maxResults"] 33 ).execute() 34 35 videos = [] 36 channels = [] 37 playlists = [] 38 urls = [] 39 40 # Add each result to the appropriate list, and then display the lists of 41 # matching videos, channels, and playlists. 42 for search_result in search_response.get("items", []): 43 if search_result["id"]["kind"] == "youtube#video": 44 videos.append("%s (%s)" % (search_result["snippet"]["title"], search_result["id"]["videoId"])) 45 urls.append("youtube.com/watch?v={}".format(search_result["id"]["videoId"])) 46 elif search_result["id"]["kind"] == "youtube#channel": 47 channels.append("%s (%s)" % (search_result["snippet"]["title"], search_result["id"]["channelId"])) 48 elif search_result["id"]["kind"] == "youtube#playlist": 49 playlists.append("%s (%s)" % (search_result["snippet"]["title"], search_result["id"]["playlistId"])) 50 51 # print("Videos:\n" "\n".join(videos),"\n") 52 53 # video = ('videos'.join(videos), 'channels'.join(channels), 'playlists'.join(playlists), 'urls'.join(urls)) 54 return models.URLField(urls,max_length=255) 55
###試したこと
return models.URLField(urls,max_length=255)
を使ったりして見ましたが、うまくできませんでした。
###補足情報
python3.5.1
django1.10
コードから何をしたいのか読み取れません。こういうときは質問には不要な要素を削って、最小のサンプルを作って質問すると良いです。あるいは、作ったコードを利用する側のコードを提示してください。
回答1件
あなたの回答
tips
プレビュー