i am writing a django app which i would like to be very loosely coupled and reusable. i was wondering what the best practices are if your app is going to be used in a larger project, and the app relied on something like jquery. how do you include jquery in your app but allow it to be overridden by the very likely event that the developer of the project already has jquery for the project?
1 Answer
You can add it through media class.
class Media:
css = {
'all': ('/static/css/styles.css',)
}
js = ['/static/js/jquery-1.6.2.min.js','/static/js/tiny_mce.js','/static/js/jquery.autocomplete.js','/static/js/ajax_select.js',]
3 Comments
poindexter12
does this class hang off of a model class? it seems from the documentation that it does. i don't have a model class in my scenario because of the ajax. do you think you could give me a concrete example of this in use?
zaan
You can use this class in form class (child of django.forms.Form or django.forms.ModelForm) or in admin (child of django.contrib.admin.ModelAdmin).
Dracontis
Erm... As zaan says, you will need Django class which support Media class. If you haven't class at all, then you must write template tag, but it is look ungly. Code there is a code in my project, in ModelAdmin class.