这个答案显示了我正在寻找的相反,因为它允许一个Site
人拥有许多Asset
对象:
# Note: This is not my code. This is opposite of what I want.
# I want the ForeignKey on the Site object.
from django.contrib.sites.models import Site
class Asset(models.Model):
site = Models.ForeignKey(Site)
有没有办法将 ForeignKey 字段添加到Site
模型中,这样一个人Asset
就可以有很多Site
对象?像这样的(非工作)代码:
from django.contrib.sites.models import Site
class UpdatedSite(Site):
asset = models.ForeignKey(Asset)
我知道我可以使用 aManyToManyField
但在我的情况下,一个Site
对象永远不会有多个Asset
对象。