Skip to content

Instantly share code, notes, and snippets.

@7mp
7mp / gist:5716322
Last active December 18, 2015 03:09
Circumventing (legacy) Django's need to add `extra`'s `select`s to GROUP BY.
# -*- coding: utf-8 -*-
# TODO FIXME HARD-CODING KLUDGE MONKEYS PATCHING EACH OTHER
# Django (1.2 at least), I DON'T LIKE YOU
class FakeSQLUnicode(unicode):
def as_sql(*args, **kwargs):
# See django.db.models.sql.compiler, get_grouping, the place with `hasattr(col, 'as_sql')
# MySQL GROUP BY doesn't work with COALESCE() in GROUP BY,
# failing with Database error 1111, "invalid use of group function".
# Solution: convert the aggregate to the `id` which is there anyway! :D
@7mp
7mp / django_phantom.py
Last active January 10, 2018 23:37
Selenium driver extensions for PhantomJS and Django (and its admin)
# -*- coding: utf-8 -*-
"""
Phantom JS test drivers for Django
Tips:
* to check a value of a (global) JS variable, one can use:
driver.execute_script('return <variable_name>')
"""
@7mp
7mp / lauantaileikit.txt
Last active May 16, 2024 14:59
Lauantaileikit
"Ciribim ciribom"
Ciribim ciribom
älä luule että uskotaan
Ciribim ciribom
sua enää ollenkaan
Tytön täytyy ymmärtää
se milloin häntä narrataan