django site framework: Which models should be associated with a site (foreign, manytomany)?

65 views Asked by At

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.

1

There are 1 answers

0
Jan Pöschko On

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 the site of an attachment using

attachment.article.site

and filter using

.filter(article__site="...")

So if there's no other sophisticated query that only works with this additional database field, I would drop it.