Posts Tagged ‘python’

django-boilerplate-layout

Sunday, September 18th, 2011

Very quickly, I’d like to introduce to you my newest github project – django-boilerplate-layout. It is my hope that for each new version of django, you can check out this project layout and just start coding. More info on what this project is on the README.markdown

django-twitter-oauth on github

Thursday, June 16th, 2011

Just a quick post to link (one of my) works in progress – django-twitter-oauth that I forked on github. It is a work in progress as I am using it on another project I’m working on currently so, hopefully, this app can only get better over time. There are a few things I may want to change (caching the access token in the session instead of always going to the DB) and, really, this has not been tested on MySQL yet (I am using sqlite3 for dev), but it should work. Works well so far. Only a few problems I have yet to start working on (off the top of my head, random BadStatusLine exception every once in a while, mainly) .

I will try to update my blog whenever I update the app with what I changed, but we’ll see.

Separating Out Django Models into Different Files

Monday, June 6th, 2011

This will be a really quick post since, for whatever reason, I could not find this information out easy on the internet. The only reason I was able to find it is due to my great and good friend, Andres Buritica’s help. Starting a Django project, then an app gives you a models.py which Django expects to house all the models. This does not seem like the best of ideas, so obviously I want to split up the models into their own files in a specific model directory. To accomplish this, you must do two things:

  1. Create a meta class for the model with a field “app_label” being set to the name of your app
  2. In your __init__.py file, import that model.

For example, if you started an app by typing out ‘python manage.py startapp foo’, you can delete your models.py file, replace it with a directory named models (what I do), and inside have an __init__.py and Bar.py files.
in Bar.py:

from django.db import models
 
class Bar(models.Model):
    bar    = models.TextField(blank=False)
 
    class Meta:
        app_label = "foo"

then in __init__.py:

from Bar import Bar

This also goes for other things specified outside of the Django “norm” I guess?
If I wanted to associate Bar with the admin, I create a subdirectory inside my app named admin, and inside it I have
BarAdmin.py

from foo.models import Bar
from django.contrib import admin
 
admin.site.register(Bar)

Inside the __init__.py for the admin subdirectory, you’d have:

import BarAdmin

Now I could be doing this all wrong but this is the only way I managed to get everything working. If there is a better way to do this, I am all ears. To you Django/Python professionals out there, this may be common knowledge but I am noobing it up right now trying to better learn Python and Django.

Python, Threading and the Global Interpreter Lock

Friday, May 21st, 2010

I am still heavy on my Python learning kick. One thing that’s always interested me is the Global Interpreter Lock and why Python doesn’t have “real” threading. I came across a talk given by David Beazley called “Mindblowing Python GIL” that was very informative. Pretty shocking really about how it works and very interesting. Obviously only watching this video would leave a bad taste in your mouth regarding Python and threading, so now I need to find another talk about why the GIL is good. There is a link in the comments to a slide show that talks about why it is good, but slides without the talk are almost useless for me.

Project Euler Problem 1

Wednesday, December 23rd, 2009

So, I’m starting this much sooner than I would have anticipated but I suddenly got the urge to start.

Problem 1 is pretty straight forward:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

(more…)

Youtube is Turning Down the Lights

Wednesday, January 28th, 2009

I couldn’t decide what to do tonight. It was either reading The Rum Diary by The Good Doctor, Hunter S. Thompson, or watch some Entourage. I am a huge fan of both. However I decided to do something that would expand my mind and entertain me.

(more…)