Skip to content

Instantly share code, notes, and snippets.

View edmenendez's full-sized avatar

Ed Menendez edmenendez

View GitHub Profile
edmenendez /
Last active August 29, 2015 14:15
Django JSON Helper
Version 0.3.8 - Ed Menendez -
Add to any Django Model definition and you will have a instance.as_json() function).
For example >> class Customer(models.Model, JSONHelper):
Latest at
import copy
import json
Interface to the FreshDesk API.
Author: Ed Menendez (
Company: Digital Haiku
Created: September 1, 2014
Example settings:
edmenendez /
Last active December 17, 2015 08:29
Django manager to pull a random row from a query
import datetime
import random
from django.db import models
from django.db.models import Count
class RandomManager(models.Manager):
def __init__(self, *args, **kwargs):
self.when_last_cached = - datetime.timedelta(minutes=10)
edmenendez /
Created May 14, 2013 00:09
Misc Django Utils. Including mail a Django Group
from django.conf import settings
from django.contrib.auth.models import User, Permission
from django.core.mail import EmailMessage, mail_admins, send_mail, EmailMultiAlternatives
from django.db.models import Q
from django.utils.html import strip_tags
def mail_group(codename, subject, message=None, debug=False, html_message=None):
perm = Permission.objects.get(codename=codename) # 'get_billing_emails'
users = User.objects.filter(Q(groups__permissions=perm) | Q(user_permissions=perm)).distinct()