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]
For
ManyToManyFields that referenceself, a reverse relationship is not created. This is because it has no use – it would contain all relations that refer to itself – which is what the forward relation does.You’ll find regardless of what you say the
related_nameshould be it will be set to%(field)s_rel_+(the trailing+prevents the relation being created).So the answer is there is no
child_setbecause you can just usef.