It's an update of snippet [https://djangosnippets.org/snippets/1376/](https://djangosnippets.org/snippets/1376/) to work with Django 1.8. With this piece of code, you can override admin templates without copy or symlink files. Just write your template and extend the target.
**CancelMixin**
A simple mixin to use with ```generic.CreateView``` and ```generic.UpdateView``` view form templates to effortlessly implement a "Cancel" button.
This smart mixin will add a URL to your context, ```{{ cancel_url }}```, that can be used as a cancel link in your form template. If no referrer URL is provided, the cancel button will link to ```default_cancel_url```, which can be overridden by view.
** **
**What It Is**
This is a JavaScript-based solution to dynamically add and remove forms in formsets and inlineformsets. It requires jQuery.
Originally based on this Snippet: https://djangosnippets.org/snippets/1389/
I have done a lot of work to make it OO, and am using it in production on pages with multiple inlineformsets, and even nested inlineformsets (I call it, "Inlineformset Inception").
My hope is that the code and example are enough to show how it works.
**Usage Details**
In the example usage, I am using a CSS class, 'light', to make every other form have a light background color. My form placeholder is an element with an ID of 'formset-placeholder' (the default). And the form selector is a class name of 'dynamic-form' (the default).
When I have time, I will create a GitHub repository with the code and completed examples.
The `post_syncdb` (Django pre-1.7) and `post_migrate` (>=1.7 and South) signals are fired for every single app. What I really wanted was one signal fired after the migration or syncdb completed. There's no official one, and all the snippets were doing horribly hacky things (and wouldn't work for South, anyway). This one will work for Django syncdb, and South migrate.
This snippets extends ModelAdmin in order to allow multi field sorting in admin tables.
Usage example:
class MyModelAdmin(MultiFieldSortableModelAdmin):
list_display = (
...
'user_full_name',
...
)
def user_full_name(self, obj):
return obj.user.get_full_name()
user_full_name.admin_order_field = ['user__first_name', 'user__last_name']`
This snippet holds your Django project from automatically changing language of the page to the best fitting one by discovering the client browser language.
I personally needed to show the page to the user for the first time in the default language (English), although there were some translations. User can still change the language (via session cookies).
Insert this middleware BEFORE the Django's `django.middleware.locale.LocaleMiddleware` in settings.
Mixin to support pagination when randomizing querysets.
Requirements: Postgres, Django Sessions
Note: This shouldn't be used on large complex datasets. It utilizes the relatively slow method of '?' randomized sorting. Use with caution.
Todo: MySQL support, Support for larger datasets
For several projects I am using generic views instead of django-admin, I needed a generic view for constance instead of using their django-admin based app.
## required
* `{% load trans%}`before using this snippets
* Add this [template filter](https://djangosnippets.org/snippets/2253/) to your custom templatetags and load it before using this snippets
* Bootstrap framework
Log Django exceptions to file. Contains snippet for both WatchedFileHandler and RotatingFileHandler handlers. Configurations mentioned are separate And only works if the DEBUG = False. Use "python manage.py runserver --no-reload" If you get file in use error.
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.