Skip to content

Instantly share code, notes, and snippets.

View mrabedini's full-sized avatar
💭
GitHub is acting like a child! #IranBan

Mohammad Reza Abedini mrabedini

💭
GitHub is acting like a child! #IranBan
View GitHub Profile
@xuhcc
xuhcc / perms.py
Last active October 16, 2018 08:59
django 1.7 migrations + django-guardian
"""
You also need to create initial migration for guardian app!
"""
from django.contrib.contenttypes.models import ContentType
from guardian.models import UserObjectPermission, GroupObjectPermission
def is_user(obj):
return obj._meta.model_name == 'user'
@eculver
eculver / Simple reversible datetime representation
Created January 5, 2011 01:24
Basic conversion of python datetime to string and back
import datetime
fmt = '%Y%m%d%H%M%S' # ex. 20110104172008 -> Jan. 04, 2011 5:20:08pm
now_str = datetime.datetime.now().strftime(fmt)
now_datetime = datetime.datetime.strptime(now_str, fmt)