Add this to any admin changelist and your actions drop-down will be replaced with user-friendly buttons.
Why mess around with templates and subclassing admin classes when you can just mangle the page with jQuery! ;-)
It also adds a 'select all' label to explain the mystery top check-box (well it was a mystery to several of my clients).
The line "if ($('div.actions option:gt(0)').length<=8)" checks that there aren't more than 8 actions and falls back to the drop-down if there are.
Requires jQuery to be loaded.
I never found a good snippet or tutorial to get the app_list (in django.admin) on other pages except the index page. So i started asking on irc j00bar has given me a very nice answer, but first i didn't know what to do with it till now.
Anyways this snippet is very handy for the people who wants this but don't know how to get it.
This is special made for the django version 1.1
Installation is quite easy, it is a context processor, so download this file put anywhere in your project, i got it in a app called cms_theme (theme and template related stuff.) and put the location in your settings.py file, example:
`TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'****cms.cms_themes.context_processors.theme',
'****cms.cms_themes.context_processors.applist',
)`
The '****' stuff is nothing, i replaced my company name with it.
Of course you may put the context processor anywhere else, that is your choice.
Good luck!
Alexander
This will use the syslog system to log your logs. This is usefull when you use WSGI and want to have a per day logging file (TimedRotatingFileHandler is not process safe, and you may lose data when using it with WSGI).
Under a debian system, you'll have to modify **/etc/rsyslog.conf** and add:
local0.* -/var/log/django/django.log
local1.* -/var/log/django/payment.log
This is some (probably) pretty dodgy code that allows for foreign keys in the admin's list_filter without using a custom FilterSpec. It overrides the django.db.models.options.Options get_field class to handle spanned relationships, i.e. list_filter=('house__room__town',) as seen in http://code.djangoproject.com/ticket/3400
I have only tested this with a double foreign key relationship('house__room'), and it worked. It hasn't been tested in production, and the troubling part of this code is probably to use of 'deepcopy'. I do add those copies back to the options instance, so there shouldn't be too much runaway copying.
Django Filebrowser (http://code.google.com/p/django-filebrowser/) provides a signal called filebrowser_post_upload. Adding this method to a model that has a FileBrowse field will cause uploaded .zip files to be detected and unzipped on the server in place, then deleted (leaving their folder behind). It will also delete the garbage __MACOSX folder created by Mac zip files.
This is probably not safe to do for publicly uploaded files. The use case here was to allow journalists to upload entire SoundSlides projects into a custom CMS.
An update to snippet 1718 (http://www.djangosnippets.org/snippets/1718/). This update lets you pass an image URL string as well as a model ImageField instance. This means that you can then create thumbnails on demand for images outside of model
This Snippet allows a view to controle the printed forms on the templates, in a similar way to the fieldsets used by the django admin.
How to Use:
In the view in question, put:
def some_view(request):
...
fieldsets = (
(u'Title 1',
{'hidden' : ('field_1', 'field_2',),
'fields' : ('field_3',)}),
(u'Title 2',
{'hidden' : ('field_5', 'field_6',),
'fields' : ('field_4',)}),)
)
return render_to_response('some.html', {'fieldsets': fieldsets})
fieldsets = (
(None,
{'hidden' : ('evento', 'colaborador',),
'fields' : ('acompanhantes',)}),
)
Next, in the html just add:
<form enctype="multipart/form-data" id="edit" method="post" ...>
...
{% include "inc/form_snippet.html" %}
...
<input type="submit" value="Submit">
</form>
Sometimes its necessary to map your django models to Java Hibernate created tables. Hibernate maps boolean field to bit(1) column instead of tinyint in django.
NOTE: tested for mysql backend only
This is how you can access the user's request in the Form or FormSet definition, e.g. to define the choices of a ChoiceField dynamically.
Either you use it for a single Form or a whole FormSet, just pass the view's request into the Form or FormSet instantiation.
This snippet is helpful if you do a lot of editing on a single large admin form (for example, in a rich text field), and want to frequently save your progress. If you press control-S, or command-S on a Mac, the admin change form will save and reload, and the page will scroll back down to where you last were.
This snippet relies on jquery, [jquery.cookie](http://plugins.jquery.com/project/cookie), and the [shortcut.js](http://www.openjs.com/scripts/events/keyboard_shortcuts/) keyboard library (which doesn't use jquery, but seemed more robust than the jquery keyboard plugins I saw). It uses a temporary cookie to remember where the page was scrolled to, to avoid having to override the admin behavior.
Note: don't put this in templates/admin/change_form.html -- the circular import causes a Django crash.
*Edit: Had forgotten to include jquery.cookie, which I was already including elsewhere.*
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.