考慮如下:有沒有辦法從M2M關係中獲取* only *相關對象的PK?
class Tag(Model):
...
class Post(Model):
tags = ManyToManyField(Tag) # a join table "post_tags" is created
post = Post.objects.get(pk=1)
post.tags.all() # this will cause django to join "tag" with "post_tags"
post.tags.values('pk') # even though pk is already in post_tags, django will still join with "tag" table
我需要的是隻的PK名單。有誰知道支持的方式,或乾淨的黑客,我可以從M2M獲取PK而無需額外連接到實際的相關表格?