I am somewhat of a Django beginner and have been trying to decouple my applications as much as possible and build it in as small re-usable pieces as possible. Trying to follow James Bennett's strategy of building re-usable apps. With that in mind, I came across this problem.
Let's say I had an app that stores information about movies:
The code would look something like this:
class Movie(models.Model):
name = models.CharField(max_length=255)
...
Now, if I wanted to add ratings, I could use django-rating and simply add a field to my model:
class Movie(models.Model):
name = models.CharField(max_length=255)
rating = RatingField(range=5)
...
This inherently mean that my Movie app is now dependent on django-ratings and if I wanted to re-use it, but no longer needed ratings, I would still have to install django-ratings or modify and fork off my app.
Now, I could get around this by use try/except with import and define the field if successful, but now my movie app is explicitly tied to the rating in the database table definition.
It seems much more sensible to separate the two models and define the relationship in the ratings model instead of the Movie. That way the dependency is defined when I use the rating, but not needed when using the Movie app.
How do you deal with this problem? Is there a better approach to separate the models?
I also wonder if there are any major performance penalties in doing this.
edit: I want to clarify that this is more of an example of the problem and a somewhat contrived one at that to illustrate a point. I want to be able to add additional information without modifying the "Movie" model every time I need to add related data. I appreciate the responses so far.