Django: How to follow ManyToMany('self') backwards
问题 class c(models.Model): f = models.ManyToManyField( 'self', blank=True, null=True, related_name='child_set' ) I can do : c.objects.get(pk="1").f But how do I get by '_set'? c.objects.get(pk="1").child_set doesn't work i need this: {name:A,parent:[]} {name:B,parent:[A]} {name:C,parent:[A,B]} C.parent.all() == [A,B] A.parent_set.all() == [B,C] 回答1: For ManyToManyField s that reference self , a reverse relationship is not created. This is because it has no use - it would contain all relations