python - Creating Reusable Django Apps? -
i of django beginner , have been trying decouple applications as possible , build in small re-usable pieces possible. trying follow james bennett's strategy of building re-usable apps. in mind, came across problem.
let's had app stores information movies:
the code this:
class movie(models.model): name = models.charfield(max_length=255) ...
now, if wanted add ratings, use django-rating , add field model:
class movie(models.model): name = models.charfield(max_length=255) rating = ratingfield(range=5) ...
this inherently mean movie app dependent on django-ratings , if wanted re-use it, no longer needed ratings, still have install django-ratings or modify , fork off app.
now, around use try/except import , define field if successful, movie app explicitly tied rating in database table definition.
it seems more sensible separate 2 models , define relationship in ratings model instead of movie. way dependency defined when use rating, not needed when using movie app.
how deal problem? there better approach separate models?
i wonder if there major performance penalties in doing this.
edit: want clarify more of example of problem , contrived 1 @ illustrate point. want able add additional information without modifying "movie" model every time need add related data. appreciate responses far.
in case, personally, i'd keep simple , leave rating
on model. have balance re-usability simplicity of implementation. it's great make things reusable, movie
model useful enough warrant work? , bad have dependency? think of these design decisions subjective. there talk year @ pycon on subject: http://blip.tv/file/4882961
Comments
Post a Comment