Skip to content

Instantly share code, notes, and snippets.

@goutham2027
goutham2027 / django_reversion.md
Last active Jul 12, 2016
using django reversion
View django_reversion.md
pip install django-reversion

Add reversion to INSTALLED_APPS

INSTALLED_APPS = [
...
...
...
View query.py
from itertools import chain
from operator import attrgetter
# ascending oreder
result_list = sorted(
chain(queryset1, queryset2),
key=attrgetter('date_created'))
# descending order
@mattmcc
mattmcc / models.py
Created Mar 27, 2013
Quick & dirty "read-only" model for using SQL views
View models.py
class ViewManager(models.Manager):
def bulk_create(self, *args, **kwargs):
raise NotImplementedError
def create(self, *args, **kwargs):
raise NotImplementedError
def get_or_create(self, *args, **kwargs):
raise NotImplementedError
@rturowicz
rturowicz / page.py
Last active Dec 19, 2018
django - intermediate admin page
View page.py
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']
@bunkat
bunkat / index.html
Created Apr 8, 2012
Timeline using d3.js
View index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Chronological Diagram of Asia</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style type="text/css">
.chart {
shape-rendering: crispEdges;
}
@josharian
josharian / django_sleep.py
Created Dec 9, 2011
Simple Django middleware that delays the processing of each request
View django_sleep.py
"""
This module provides very simple Django middleware that sleeps on every request.
This is useful when you want to simulate slow response times (as might be
encountered, say, on a cell network).
To use, add this middleware, and add a value for SLEEP_TIME to your settings.
Possible future feature: Look for an X-Django-Sleep header on each request,
to let the client specify per-request sleep time.
View Textos a profundidad.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gonzalo-bulnes
gonzalo-bulnes / comunas.json
Last active Apr 30, 2020
Comunas de Chile (seed Ruby on Rails, JSON) - (see also https://github.com/gonzalo-bulnes/chilean_cities)
View comunas.json
[
{
"name": "Arica",
"code": "15101",
"provincia": "Arica",
"region": "Arica y Parinacota",
"region_number": "XV",
"region_iso_3166_2": "CL-AP"
},
{
@MrYoda
MrYoda / views.py
Last active Aug 10, 2020
Python 3, Django 1.9+: Excel file creation and send on-the-fly with XlsxWriter & BytesIO
View views.py
import xlsxwriter
from io import BytesIO
from django.http import StreamingHttpResponse
from django.views.generic import View
def get_foo_table_data():
"""
Some table data
"""
@mdesantis
mdesantis / upgrade-postgres-9.6-to-10.md
Last active Aug 17, 2020 — forked from delameko/upgrade-postgres-9.5-to-9.6.md
Upgrading PostgreSQL from 9.6 to 10 on Ubuntu 16.04
View upgrade-postgres-9.6-to-10.md

TL;DR

Install Postgres 10, and then:

sudo pg_dropcluster 10 main --stop
sudo pg_upgradecluster 9.6 main
sudo pg_dropcluster 9.6 main