Django What is reverse relationship?

后端 未结 2 1698
旧时难觅i
旧时难觅i 2020-11-28 05:59

Can someone tell me what is reverse relationship means? I have started using Django and in lot of places in the documentation I see \'reverse relationship, being mentioned.

2条回答
  •  青春惊慌失措
    2020-11-28 06:31

    In Django 2.0 you would define a ForeignKey as follows

    mainclient = models.ForeignKey( MainClient, on_delete=model.CASCADE, related_name='+')  
    

    the related_name='+' would cancel the default reverse relationship that Django sets up, so in the previous example, you would not be able to query the profiles using group.profiles.all().

提交回复
热议问题