-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made Setting for test,and merged before branch main #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下の点を直してみてください!
①今回のいいね機能の実装では非同期通信で実装する必要があるため、Ajax の FetchAPI(JavaScriptのなんか)を使ってください!
②いいね機能の実装範囲とは違ってしまうのですが、ホーム画面において他者のプロフィールのリンクを貼ってください。今のままだとURLをいじらないとアクセスしたい相手のプロフィールに飛ぶことが出来ないので...
flake8(linter)のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
ご指摘点、修正しました! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よく書けていると思います!
ただ、何ヶ所か疑問に思った部分があったので返信or修正お願いします!
@@ -15,3 +15,18 @@ class Tweet(models.Model): | |||
|
|||
content = models.CharField(max_length=100) | |||
created_at = models.DateTimeField(default=timezone.now) | |||
|
|||
|
|||
class Favorite(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewではLike・Unlikeとしている一方で、ModelではFavoriteと命名した理由は何ですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考記事に引っ張られた命名になっていたと思います。
tweets/views.py
Outdated
i = 0 | ||
for tweet in tweets_list: | ||
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count() | ||
tweet.number = i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tweet.numberは何のための数値ですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tweet.numberは、tweets/home.htmlにおいて、Ajax操作を行う時、それぞれのツイートに対して別々のタグを振り分けるためのIDとして扱っています。
tweets/views.py
Outdated
except Tweet.DoesNotExist: | ||
return HttpResponseNotFound("Tweet does not exist") | ||
else: | ||
_, created = Favorite.objects.get_or_create(user=user, tweet=tweet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdは使われていますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdは使われていません。
これは、もともと Favoriteが作られたか作られていないかで動作を分けていたのですが、
よくよく考えてみたらその動作は必要なく、その名残がそのまま残っていたものでした。
次のコミットでは、フラグの代入部分を消し、等式の右側のみが残る形になると思います。
accounts/views.py
Outdated
@@ -63,6 +65,15 @@ def get_context_data(self): | |||
def userprofile_view(request, username): | |||
user = User.objects.get(username=username) | |||
tweets_list = Tweet.objects.select_related("user").filter(user=user) | |||
i = 0 | |||
for tweet in tweets_list: | |||
if Favorite.objects.filter(user=request.user, tweet=tweet).exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for文内でのDB操作は極力避けましょう(N+1問題)
request.userがいいねをしたツイートIDを取得することは、for文外でも可能だと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N+1問題がたくさん...
こちらも次のコミットで改修します!
accounts/views.py
Outdated
tweet.liked = True | ||
else: | ||
tweet.liked = False | ||
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いいね数も同様です。
tweets/views.py
Outdated
i = 0 | ||
for tweet in tweets_list: | ||
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count() | ||
tweet.number = i + 1 | ||
i += 1 | ||
if Favorite.objects.filter(user=request.user, tweet=tweet).exists(): | ||
tweet.liked = True | ||
else: | ||
tweet.liked = False | ||
tweets_number = tweets_list.count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N+1問題。
Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細 |
Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細 |
Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細 |
マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細 |
Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細 |
Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
レビューありがとうございました! |
受講生の確認事項
1次レビュアーの確認事項