Django should have OneToManyField

A bit of background here about ForeignKey (many to one): If you have Order and OrderItem models, your order FK is in OrderItem model, from OrderItem model point of view, it’s Many OrderItem to One Order, in other words ManyToOne. What this implies is you need to have Order records before OrderItem records. Now, why… Read More »

What’s wrong with this statement?

This morning I made a code change to log some stuff in a core package and created a pull request, the change was very simple: from self.execute_command(command, cwd=os.path.dirname(infile)) to logger.debug(self.execute_command(command, cwd=os.path.dirname(infile))) One of the team lead pointed out the statement has a problem, and it was a life saver, but I won’t tell you why… Read More »

Python OpenCV Facial Detection On OSX

Just a code snippet to demo Python script using OpenCV import cv2, time cap = cv2.VideoCapture(0) time.sleep(1) cascade = cv2.CascadeClassifier(“haarcascade_frontalface_alt.xml”) def detect(image): #faces = cascade.detectMultiScale(img, 1.1, 2,, (20,20), (200,200)) faces = cascade.detectMultiScale(image) for _face in faces: cv2.rectangle(image, (_face[0], _face[1]), (_face[0]+_face[2], _face[1]+_face[3]), (255,255,255)) def repeat(): ret, image = detect(image) cv2.imshow(“w1″, image) cv2.waitKey(1) while True:… Read More »

RequireJS + Zurb Foundation

“use strict”; require.config({ baseUrl: ‘static’, paths: { jquery: ‘bower_components/jquery/dist/jquery’, foundation: ‘bower_components/foundation/js/foundation’, }, shim: { ‘foundation': { deps: [‘jquery’] }, } }); require([‘foundation’], function(f){ $(function(){ alert(1); }); });

django-rest-framework: api versioning

Django Rest Framework is a very solid api framework, but it doesn’t provide out-of-box versioning mechanism, here is my attempt to implement version specific APIs. The goal is to achieve something like http://localhost:8000/api/(resource)/ http://localhost:8000/api/v1/(resource)/ plus allowing clients to specify the version in request header (X-Version), here is how we did it. Structure in side the… Read More »