Skip to content

Instantly share code, notes, and snippets.

marceloleiva / .env-example
Created Apr 3, 2020 — forked from gjbagrowski/.env-example
Django-environ example
View .env-example
# project-repo/app/settings/.env-example
DEBUG=true # never on production, will cause settings including api keys to leak
marceloleiva /
Created Jul 7, 2019 — forked from eerien/
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
marceloleiva /
Created Jul 21, 2018 — forked from rturowicz/
django - intermediate admin page
# 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']
marceloleiva /
Created Apr 3, 2018 — forked from perrygeo/
Generate UML diagram of django app models
apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in
python graph_models trees -o test.png
marceloleiva /
Created Jun 6, 2017 — forked from cecilemuller/
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

marceloleiva /
Created Apr 27, 2017 — forked from MrYoda/
Python 3, Django 1.9+: Excel file creation and send on-the-fly with XlsxWriter & BytesIO
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
marceloleiva / Buscar texto con
Created Oct 17, 2016
Buscar texto con re created by marceloleiva -
View Buscar texto con
import re
texto = 'Supermercado (1,10,5)'
busqueda_coordenada ='(.+)(\(.{5,}\))', texto)
if busqueda_coordenada:
if len(busqueda_coordenada.groups()) >= 2:
texto =
coordenada = re.sub('[()]', '',',')
import chardet
def determinar_encoding(input_file='despachos.csv'):
file = open(input_file, 'rb').read()
encoding = chardet.detect(file)
if encoding:
return encoding['encoding']
return None
pip install django-reversion

Add reversion to INSTALLED_APPS

marceloleiva /
Created Dec 10, 2015 — forked from neara/
Django Class Based Views and Inline Formset Example
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from models import Sponsor, Sponsorship
class SponsorForm(ModelForm):
class Meta:
model = Sponsor