Skip to content

Instantly share code, notes, and snippets.

cls = self.__class__
if klass is None:
klass = cls
elif not not issubclass(klass, cls):
klass = type(klass.__name__, (klass, cls), {})
@charettes
charettes / gist:6296424
Created August 21, 2013 16:03
Registering mutant dynamic models to reversion.
from django.dispatch.dispatcher import receiver
from mutant.signals import mutable_class_prepared
import reversion
@receiver(mutable_class_prepared)
def register_reversion(sender, existing_model_class, **kwargs):
reversion.register(sender) # Register the newly created model class
if obsolete_class: # Unregister the obsolete model class
reversion.unregister(existing_model_class)
apps_a = Apps()
apps_b = Apps()
class A(models.Model):
class Meta:
apps = apps_a
class B(models.Model):
a = models.ForeignKey(A)
@charettes
charettes / gist:4d65686bc89f187e53fd
Created September 4, 2014 21:05
to_field inline fix
From a3c6349b2c799bd45c3f250d0c03b81f5b03a91e Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Thu, 4 Sep 2014 17:04:53 -0400
Subject: [PATCH] Inline fix.
---
django/contrib/admin/options.py | 10 +++++++++-
tests/admin_views/admin.py | 13 ++++++++++++-
tests/admin_views/models.py | 12 ++++++++++++
tests/admin_views/tests.py | 5 +++++

Keybase proof

I hereby claim:

  • I am charettes on github.
  • I am charettes (https://keybase.io/charettes) on keybase.
  • I have a public key whose fingerprint is 8557 62CE 0C47 C935 9480 44AA 72AF 89A0 B1B4 EDB3

To claim this, I am signing this object:

(django-sundial)simon@simon-laptop:~/workspace/django-sundial$ python setup.py bdist_wheel --universal
running bdist_wheel
running build
installing to build/bdist.linux-x86_64/wheel
running install
running install_egg_info
running egg_info
creating django_sundial.egg-info
writing requirements to django_sundial.egg-info/requires.txt
writing django_sundial.egg-info/PKG-INFO
diff --git a/django/test/runner.py b/django/test/runner.py
index 1106c52..e053bd3 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -211,6 +211,27 @@ class DiscoverRunner(object):
result = self.run_suite(suite)
self.teardown_databases(old_config)
self.teardown_test_environment()
+ from itertools import groupby
+ def keyfunc(test):
@charettes
charettes / test.py
Created December 23, 2015 23:12
Python 3.5 OrderedDict bug
import collections
import gc
import weakref
def create_reference():
class A(object):
pass
class B(A):
parents = collections.OrderedDict([
from django.db import router
from django.db.models import deletion
def ALLOW_MIGRATE_CASCADE(collector, field, sub_objs, using):
opts = sub_objs[0]._meta
if router.allow_migrate(using, opts.app_label, opts.model_name):
deletion.CASCADE(collector, field, sub_objs, using)
# Add the common tests module as an application to allow its models
# table to be created even if they are not part of the common migations.
app_config = AppConfig.create(__package__)
app_config.label = 'common_tests'
app_config.import_models(apps.all_models[app_config.label])
apps.app_configs[app_config.label] = app_config
apps.clear_cache()