0
0

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.

for model in model_or_iterable: TypeError: 'type' object is not iterable とかいうエラーが出た

Posted at

djangoでフォロー機能を実装しているとき、中間テーブルの値を取り出したくて(というかフォローしてるかどうか調べたかった)、

view.py
result = followAndFollower.objects.filter(follower__username=context['user'].username).filter(follow__username=username)

と書いたところ、

for model in model_or_iterable: TypeError: 'type' object is not iterable

とかいうエラーが出た。
Django初心者なので、ん、.objectsって書き方間違ってる?
とか、
英語初心者なので、objectsのスペル違う?
とか色々調べたが解決せず。

とほほ、と途方にくれながら、エラーメッセージ全文コピぺしてgoogleに聞いたところ、
以下のようなサイトが....

stackoverflow

これによると、
you forgot to subclass it from models.Model
(お前models.Model書くの忘れてんちゃう?)

とのこと。まさかそんなことするわけ、初心者だしそんな変なことしてねえよと思い恐る恐るmodels.pyを見てみると、、、

models.py
class followAndFollower():

あっ、、、、、土下座

ということでそもそもテーブルすら作られてなかったっぽい、南無。

そもそもエラーメッセージをターミナルで毎回確認しているんですが普通はどうやってチェックするんだ?初心者過ぎて何もわかりません泣
誰か教えていただけると泣いて喜びます。

0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?