Skip to content

Instantly share code, notes, and snippets.

@madaboutcode
Last active August 29, 2015 13:57
Show Gist options
  • Save madaboutcode/9384750 to your computer and use it in GitHub Desktop.
Save madaboutcode/9384750 to your computer and use it in GitHub Desktop.
django cheats, reference

#Query

# group by, count and sort
Model.objects.values('ingredient','category').annotate(count=Count('ingredient')).order_by('-count')

Shortcuts

# dictionary comprehension
d = { k:v for k,v in collection }

Display

#output with no newline 
sys.stdout.write('.')

Iterations

# dictinary iteration
for k, v in d.iteritems()

Date operation

# parse string to date
datetime.datetime.strptime('07/04/2014','%d/%m/%Y').date()

pip install

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment