r0ysue肉絲大數(shù)據(jù)安全進(jìn)階
訪問多對多值(Many-to-Many Values)
多對多和外鍵工作方式相同,只不過我們處理的是QuerySet而不是模型實(shí)例。 例如,這里是如何查看書籍的作者:
>>> b = Book.objects.get(id=50) >>> b.authors.all() [<Author: Adrian Holovaty>, <Author: Jacob Kaplan-Moss>] >>> b.authors.filter(first_name='Adrian') [<Author: Adrian Holovaty>] >>> b.authors.filter(first_name='Adam') []
標(biāo)簽: