0
This answer显示的就是我要找的逆,因为它允许一个Site
有许多Asset
对象:有没有办法在Django Sites Framework的Site模型中添加一个ForeignKey?
# 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)
我明白,我可以用一个ManyToManyField
但对我来说一个Site
对象将永远不会拥有多个Asset
对象。
我的问题明确规定,我不想在这两个方向上一个ForeignKey。我希望它在网站模型上。 – YPCrumble
我不认为你有时间在不到30秒的时间内通过理解阅读我的答案。我指的是陈述你的代码是现在的,所以请善待并阅读完整的答案。 – iklinac
我把我的问题的特异性提高到了11。 – YPCrumble