This file contains hidden or 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
#!/bin/sh | |
# Make executable, and save in .git/hooks | |
# Happily, flake8 will ignore non-python files | |
git diff --cached --name-only --diff-filter=ACM | flake8 |
This file contains hidden or 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 LengthLookup(models.Transform): | |
lookup_name = 'length' | |
def as_sql(self, compiler, connection): | |
lhs, params = compiler.compile(self.lhs) | |
return 'CHAR_LENGTH(%s)' % lhs, params | |
# SQLite doesn't implement CHAR_LENGTH, but its implementation of LENGTH conforms | |
# with standard SQL CHAR_LENGTH (i.e. number of chars, not number of bytes) | |
def as_sqlite(self, compiler, connection): |
This file contains hidden or 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
import subprocess | |
dbname = 'mydbname.{}.db'.format( | |
subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD',]).rstrip() | |
) | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', | |
'NAME': path.join(BASE_DIR, dbname), | |
} |
This file contains hidden or 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
# Add the mixin to the default admin objects | |
from django.contrib.auth import get_user_model | |
from django.contrib.auth.admin import UserAdmin as ContribUserAdmin | |
from django.contrib.auth.forms import UserChangeForm as ContribUserChangeForm, \ | |
UserCreationForm as ContribUserCreationForm | |
from accounts.forms import CaseInsensitiveUsernameMixin # adjust if forms.py is not in `accounts` app | |
class UserChangeForm(CaseInsensitiveUsernameMixin, ContribUserChangeForm): |