according to the docu this is pretty straight forward:
class Article(models.Model):
headline = models.CharField(max_length=200)
# ...
site = models.ForeignKey(Site)
but what if i have an additional Model? i.e.:
class ArticleAttachment(models.Model):
file = models.FileField(upload_to="foo/bar")
# ...
ArticleAttachment() is already associated with an Article (which is already associated with a site). should i still add the foreignkey to the site? and if yes/no, why?
(performance is not an issue.)
thx.
Adding the redundant foreign key would only help performance if you want to display all the article attachments with a given
site
, for instance. Otherwise (esp. if you don't care about performance at all), it doesn't really help you, it just introduces more "maintenance" work. You can always access thesite
of an attachment usingand filter using
So if there's no other sophisticated query that only works with this additional database field, I would drop it.