Skip to content

Instantly share code, notes, and snippets.

View FrancoisConstant's full-sized avatar
🏠
Working from home

François Constant FrancoisConstant

🏠
Working from home
View GitHub Profile
@FrancoisConstant
FrancoisConstant / fields.py
Created July 14, 2021 02:22
Django tests via SQLITE with Postgres Array and JSON fields
import json
from django.conf import settings
from django.contrib.postgres.fields import (
JSONField as DjangoJSONField,
ArrayField as DjangoArrayField,
)
from django.db.models import Field
@FrancoisConstant
FrancoisConstant / partial-word-haystack-elasticsearch
Last active April 18, 2017 19:14
Django - Haystack - Elasticsearch - partial word
class MyIndex(SearchIndex):
text = EdgeNgramField(document=True, use_template=True)
# >edge... instead of indexes.CharField
# found here: http://stackoverflow.com/questions/4391631/how-do-i-do-a-partial-field-match-using-haystack
@FrancoisConstant
FrancoisConstant / Django Test - Django WebTest
Created June 8, 2014 22:05
Same "interface" for Django test & WebTest
from django.test import TestCase
from django_webtest import WebTest
__author__ = 'Francois CONSTANT'
class SimpleTest(TestCase):
"""
Based on django TestCase
adapted for unit tests and functional tests not involving forms / users logged-in etc.
@FrancoisConstant
FrancoisConstant / mysql-remove-duplicates
Created October 17, 2011 03:57
Find and remove duplicates in table - keeps only distinct values (without a temp table)
SELECT people_user.*
FROM people_user
LEFT OUTER JOIN (
SELECT MIN(user_id) as MinId, email
FROM people_user
GROUP BY email
) as KeepRows ON
people_user.user_id = KeepRows.MinId
WHERE
KeepRows.MinId IS NULL;