Skip to content

Instantly share code, notes, and snippets.

View marceloleiva's full-sized avatar

Marcelo Leiva marceloleiva

View GitHub Profile
@magopian
magopian / fix_permissions.py
Created November 19, 2013 11:00
Django admin command to "fix permissions" (create them properly for proxy models). This is needed because of the following bug in Django (not fixed as of 1.6): https://code.djangoproject.com/ticket/11154
# -*- coding: utf-8 -*-
"""Add permissions for proxy model.
This is needed because of the bug https://code.djangoproject.com/ticket/11154
in Django (as of 1.6, it's not fixed).
When a permission is created for a proxy model, it actually creates if for it's
base model app_label (eg: for "article" instead of "about", for the About proxy
model).
@mdesantis
mdesantis / upgrade-postgres-9.6-to-10.md
Last active October 11, 2021 08:11 — forked from delameko/upgrade-postgres-9.5-to-9.6.md
Upgrading PostgreSQL from 9.6 to 10 on Ubuntu 16.04

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
@X-Wei
X-Wei / sliver_appbar_with_tabs.dart
Created July 29, 2018 11:36
Demo of using SliverAppbar with tabs.
// Sliver appbar with tabs.
// Adapted from: https://stackoverflow.com/a/50858058
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: SilverAppBarWithTabBarScreen(),
));
class SilverAppBarWithTabBarScreen extends StatefulWidget {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josharian
josharian / django_sleep.py
Created December 9, 2011 22:38
Simple Django middleware that delays the processing of each request
"""
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.
@rturowicz
rturowicz / page.py
Last active December 19, 2018 11:50
django - intermediate admin page
# 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']
@mattmcc
mattmcc / models.py
Created March 27, 2013 00:24
Quick & dirty "read-only" model for using SQL views
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
from itertools import chain
from operator import attrgetter
# ascending oreder
result_list = sorted(
chain(queryset1, queryset2),
key=attrgetter('date_created'))
# descending order
@goutham2027
goutham2027 / django_reversion.md
Last active July 12, 2016 17:40
using django reversion
pip install django-reversion

Add reversion to INSTALLED_APPS

INSTALLED_APPS = [
...
...
...