我有一个django模型,叫做Person和PersonRelation
class Person(model.Models):
person_name = models.charfield(max_length=255, blank=False)
person_address = models.charfield(max_length=255, blank = False)
class PersonRelation(model.Models):
person = models.ForeignKey(Person, on_delete=models.CASCADE, related_name='sibling_of')
person_relation = models.ForeignKey(Person, on_delete=models.CASCADE)
现在让我们说:
SAM is Related to JOHN
SMITH is Related to JOHN
TOM is related to SMITH
如何从数据库中获取所有相关的兄弟姐妹
相关兄弟姐妹的所需输出: 山姆-约翰-史密斯-汤姆
所以我使用递归:)
相关问题 更多 >
编程相关推荐