时间:2021-07-01 10:21:17 帮助过:22人阅读
使用交互进行检索
In [1]: from blog.models import Entry, Blog In [2]: entry1 = Entry.objects.create(name=‘alen‘) #创建对应的one项(Entry) In [3]: entry2 = Entry.objects.create(name=‘max‘) In [4]: entry3 = Entry.objects.create(name=‘carl‘) In [6]: blog1 = Blog.objects.create(name=‘alen_blog1‘, entry=entry1) #创建对应many项 In [8]: blog1.entry #(many)从many端进行检索到one Out[8]: alen In [9]: blog1.entry_id Out[9]: 1 In [10]: entry1.blog_set #(one)它所对应的blog(many)都有哪些 Out[10]: <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager at 0x7f438ce2db00> In [11]: entry1.blog_set.all() Out[11]: <QuerySet [alen_blog1]>
如何把这这种对应的结果关系如何在web界面实现?
django_4数据库2——表外键
标签:reverse obj int 结果 交互 实现 manager desc style