Django模型,循环外键

4
如何建模以下关系:
class Country(models.Model):
  # The capital city of this country
  capital = models.ForeignKey(City)
  ## other country stuff

class City(models.Model):
  # The country where this city lies in
  country = models.ForeignKey(Country)
  ## other city stuff

这显然无法编译。(在国家的定义中,城市未定义)。有什么建议吗?

1个回答

3

可以运行,但需要添加related_name参数。已编辑解决方案以包括此参数。 - Scrontch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接