今天发现objects.get()和objects.filter()返回的对象不一样
在shell的具体内容如下:
>>> from learning_logs.models import Topic
>>> t = Topic.objects.get(id = 1)
>>> type(t)
<class 'learning_logs.models.Topic'> #返回model对象
>>> t.entry_set.all()
<QuerySet [<Entry: the first...>, <Entry: the second...>]> #返回QuerySet对象,即查询集
>>> tt = Topic.objects.filter(id = 1)
>>> type(tt)
<class 'django.db.models.query.QuerySet'> #返回
>>> tt.entry_set.all()
Traceback (most recent call last): #不能通过外链获取数据
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'entry_set'
可见objects.all()和objects.filter()返回的都是QuerySet,即查询集。
不可通过外键的类小写+下划线+set获取数据。