Skip to content

Instantly share code, notes, and snippets.

View jrobichaud's full-sized avatar

Jules Robichaud-Gagnon jrobichaud

View GitHub Profile

django autocomplete filtering

Context

If you need to override an autocomplete's behaviour based on its use in a django form, it is how I managed to do it.

Normally you would use formfield_for_foreignkey but when using autocomplete_fields is not taken in account by django admin.

Note: this is not dynamic based based on the values in the form

static file to add

@Flexonze
Flexonze / test_pgbulk.py
Last active January 19, 2023 21:02
django-pgbulk vs Django's bulk_create and bulk_update
from myapp.models import MyModel
from django.test import TestCase
import pgbulk
from time import perf_counter
class TestPgBulk(TestCase):
@classmethod
def setUpTestData(cls):
cls.number_of_objects = 25_000
@bblanchon
bblanchon / example.py
Created April 9, 2021 09:03
Django Subquery Aggregate (Count, Sum...)
from django.db.models import OuterRef
weapons = Weapon.objects.filter(unit__player_id=OuterRef('id'))
units = Unit.objects.filter(player_id=OuterRef('id'))
qs = Player.objects.annotate(weapon_count=SubqueryCount(weapons),
rarity_sum=SubquerySum(units, 'rarity'))
@tomcanac
tomcanac / react-redux.md
Last active April 3, 2020 16:38
Reads and links to bootstrap your React/ Redux skillz

First, install those two extensions:

  • react dev tools
  • redux dev tools

Ok now you can keep reading!

JavaScript/ ES[0-9]*

@KavenTheriault
KavenTheriault / profiling.md
Created December 23, 2019 15:23
Python memory profiling

Use de "track_memory" decorator on your functions.

@elaberge
elaberge / unitySizeAnalyzer.sh
Created November 4, 2016 22:56
Unity App Size Analyzer
#!/usr/bin/env bash
function dumpBundle {
FILE=$1
OUTDIR=$2
LZMADIR=$3
OUTPATH="$OUTDIR/$FILE"
LZMAPATH="$LZMADIR/$FILE"
mkdir -p $(dirname "$OUTPATH")
@sli
sli / ips.py
Last active January 9, 2024 22:41
Python IPS patcher.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# IPS Patcher
# Copyright (©) itari 2014
# Do whatever you want with this, I don't care. :D
#
# Modified by sli to work on the command line and with
# Python 3. Who even uses Tkinter anymore?
@javierarques
javierarques / protractorAPICheatsheet.md
Last active March 3, 2025 17:08
Protractor API Cheatsheet
@horsman
horsman / FixAssemblys
Created April 29, 2015 16:19
FixUnityAssemblys
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
public class ReimportUnityEngineUI
{
[MenuItem( "Assets/Reimport UI Assemblies", false, 100 )]