- Want to pretend an object is a ModelAdmin? Check out the HaystackResultsAdmin
- Need to fake a changelist for using in the
{% pagination %}
template tag? FakeChangeListForPaginator - Need to mount a ModelAdmin for a model that doesn't exist? Make an unmanaged model: HaystackResults
- Need to mount a second modeladmin for a model which has already been added? Use a proxy model. I actually don't have an app that does this, as far as I can
grep
. - Need to change the way the admin looks without replacing a substantial number of the templates? thadminjones
- Want frontend editing using the admin to do so? Look upon the terrifying face of [adminlinks](https://github.com/kezabelle/django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.admin import UserAdmin | |
from django.contrib.auth.models import User | |
from django.contrib.auth import login, get_backends | |
from django.core.exceptions import PermissionDenied | |
from django.http import HttpResponseRedirect | |
from django.contrib import messages | |
from django.core.urlresolvers import reverse | |
from django.conf import settings | |
from django.contrib import admin | |
from django.contrib.admin.sites import NotRegistered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[global] | |
timeout = 15 | |
download_cache = /home/whatever/pipcache | |
use-wheel = true | |
wheel-dir = /home/whatever/pipwheels | |
find-links = /home/whatever/pipwheels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoItLazy(object): | |
def __iter__(self): | |
from django.contrib import admin | |
admin.autodiscover() | |
yield url(r'^admin/', include(admin.site.urls)) | |
def __reversed__(self): | |
return reversed(tuple(iter(self))) | |
def __radd__(self, other): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
itin_ids = EventItinerary.objects.all().values_list('itinerary', flat=True) | |
places = Schedule.objects.filter(itinerary__in=itin_ids).distinct().values_list('place', flat=True) | |
destins = Place.objects.filter(pk__in=places) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function($, window, document, undefined) { | |
var totop; | |
var show_at; | |
var already_shown; | |
var didscroll; | |
var update_didscroll; | |
var maybe_should_display; | |
var move; | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import patterns, include, url | |
from uuidfield import UUIDField | |
# Fix the bloody UUID field so that we can do prefetching. | |
UUIDField._old_to_python = UUIDField.to_python | |
def maybe_fix_to_python(self, value): | |
return unicode(UUIDField._old_to_python(self, value=value)) | |
UUIDField.to_python = maybe_fix_to_python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AllowedHosts(object): | |
__slots__ = ('defaults', 'sites', 'cache') | |
def __init__(self, defaults=None, cache=True): | |
self.defaults = defaults or () | |
self.sites = None | |
self.cache = cache | |
def get_sites(self): | |
if self.cache is True and self.sites is not None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def function(**kwargs): | |
Thing.objects.create(**kwargs) | |
Thing2.objects.get_or_create(**kwargs) | |
# desired usage: | |
transaction.let_the_objects_buildup() | |
try: | |
function(a=1, b=2, c=3) | |
finally: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyForm(Form): | |
def __init__(self, request, *args, **kwargs): | |
user = request.user | |
super(MyForm, self).__init__(*args, **kwargs) | |
def my_fake_validator(value): | |
return my_real_validator(value, user) | |
# can't remember if this is the right syntax | |
self.fields['myfield'].validators.append(my_fake_validator) |