Greg Aker

Entries Tagged with: Django

A Django Podcast

Filed in: Announcements, Django

May 7, 2012

Along with fellow jazz musician and Djangonaut Bryan Helmig, I dropped the first episode of A Django Podcast this afternoon on 3rd Avenue Radio

We think we have some interesting things in store. If there's anything you'd like to have covered, please don't hesitate to tweet us @DjangoPodcast.

Special thanks to Matt Wilson for giving us permission to use his tune The Scenic Route off of his record aptly titled The Scenic Route. Matt's records are nothing but sonic love and you should check them out!

Read More

How does Django's class-based ListView work?

Filed in: Django

April 20, 2012

Yesterday we looked at the generic class-based TemplateView. For this installment of looking under the hood at Django class-based views, let's look at the List View. (take a peek at that class now)

Check it out, there's nothing to it, or is there?

It subclasses BaseListView and mixes MultipleObjectTemplateResponseMixin. Let's visualize how that works.


subclasses: TemplateResponseMixin

methods: get_template_names

class properties: template_name_suffix

This is pretty straightforward. We know what TemplateResponseMixin does, so we can skip that.

However, look at get_template_names() in that mixin. It looks at the type of object we pass to it, and tries to ...

Read More

How do Django class-based views work?

Filed in: Django

April 19, 2012

Django version 1.3 released new generic class-based views. While these are wickedly cool, some of the documentation is a bit hard to see exactly what you can do with them. How about some simple use cases and dive into the code so we can learn how these work.

Let's start by reviewing what is in the documentation. We'll replace django.views.generic.simple.direct_to_template with django.views.generic.TemplateView.

We can directly replace it in like so:

from django.conf.urls.defaults import patterns, url
from django.views import generic

urlpatterns = patterns('',
    url(r'^about ...

Read More

oAuth & the 37 Signals API

Filed in: Python, Django

February 25, 2012

I started what was supposed to be a quick and fun Django project using the Basecamp API. The lack of documentation in their API makes me want to punch a litter of puppies. (This is a joke, puppies are the best)

To help prevent you from punching puppies and rather than trudge through their APIs Google Group, here's what I've figured out. I'm using Python Requests because it's fantastic. If you don't use it stop the insanity, and make your life easier by using it. Additionally, my code examples are within the context of Django ...

Read More

Simple Desktops for the Mac!

Filed in: Announcements, Blobbing, Django

September 7, 2011

I'm completely stoked that the Simple Desktops app for the Mac is now available in the App Store. I took over the reigns of site development from Kenny Meyers in early 2011. Since then, Tom Watson and I have been trucking along making a lot of small tweaks leading up to this app.

Simple Desktops

I introduced Tom to Justin Voss who by day is a Java Programmer at a very large Enterprise here in Columbia, MO, but by night is an amazing Cocoa and Django developer. The collaboration on this was a ball. Tom had the vision, Justin made it ...

Read More

Know what ORMs and Query Builders do!

Filed in: Django, ExpressionEngine, CodeIgniter

September 2, 2011

ORMs and Query Builders such as the Django ORM and CodeIgniter Active Record classes are great time savers. But you can get yourself into performance trouble if you're not paying attention to what these are doing behind the scenes. I think the biggest mistake people make is they use tools like this as crutches for not understanding how to write simple SQL statements. Don't fall into this group! If you're in it, work hard to get out!

I'll show a couple of examples from both to illustrate how you can give your applications a performance boost ...

Read More

Testing Django views that rely on session variables.

Filed in: Django

August 29, 2011

I'm working on a Django project where I rely on some session variables for logged in users in the templates. Being relatively inexperienced unit testing Django views, but wanting to become a bad-ass, I was having a tough time figuring out how to get session variables working in my test methods.

The basic test class looked like:

from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from myapp.models import Blog

class BlogAdminTestCase(TestCase):

    def setUp(self):
        self.client = Client()

        s = self.client.session
        s['the_answer_to_life_and_everything'] = 42

    # Actual Tests Here...

However, every time I ...

Read More

Site Updates

Filed in: Python, Nginx, Django, Blobbing

December 16, 2010

I pushed some updates to my site here earlier this week. Updated to Django rev 14870, implemented Xapian with Haystack, ditched categories and moved to django-taggit.

So here's a quick and simple Django template tag I came up with that reads the file modification time of css/javascript files and appends a v=n query string.

from django import template
from django.conf import settings
from os.path import join, getmtime

register = template.Library()

def static_asset(filename):
    {% load static_asset %}
    <link rel="stylesheet" href="{% static_asset "css/main.css" %}" type="text/css">

    Renders a link like:
    <link rel="stylesheet ...

Read More