tags:

views:

179

answers:

1

Hi,

I am wondering if this is a good practice. I usually have re-usable django-apps and python lib's under "lib" directory and it works good. Then I have "templates" directory directly under project root and I copy the default app templates from lib/django-app/templates to my project "templates" directory and modify my layout changes.

Now sometime I need to change/modify behavior of re-usable apps for the site in question, so I would like to create a "new app" under my project and modify stuff as needed. This way I can upgrade the re-usable app nicely.

Is this a way to go? are there better ways?

Thanks.

+2  A: 

Grabbing a copy and modifying re-usable app directly isn't really a good way to go, in my opinion. That way, when you re-usable app gets new features or its bugs are fixed, you can't easily pull a new version of the app.

Better way to do it is to modify the parts that don't suit your needs by overriding them, but leaving the app intact. Let's take example of Django's comments app from contrib. When you don't have all the necessary fields in comment model, you're supposed to modify it by creating custom model for comment that inherits the original, and add required features this way. From documentation:

from django.contrib.comments.models import Comment

class CommentWithTitle(Comment):
    title = models.CharField(max_length=300)

Now, I've modified the comments app, and I can also update the source for comment app without having to worry about conflicts. You don't have to add something to be able to use this, it works just as well when getting rid of something or changing things.

With views and templates, it's a bit of a bad practice to modify the app-provided templates directly. I prefer doing this by actually having a keyword argument to the view specifying the template. If I want to replace the default template with my own, I can just specify the new one from url configuration. Now, I don't have to touch the view for changing the template, and the url configuration clearly says that I'm using my own instead of using the default one.

af
Thanks for the clarification in detail. You answered all my questions :)
wailer