Django Lifestream part 2

Jan. 27, 2010

Last time, we defined our Lifestreaming application. We broke it down into two models:

  1. Sources: where the streams come from. Examples would be your Reddit items, Google Reader shared items, and your Tweets.
  2. Entries: each sources has many entries. Our application will aggregate these entries from their various streams into one.

In the previous post we laid the basic parts of the Sources model. Now on to the Entry model:

class Entry(models.Model):
    """Entry
        An individual entry from a Source."""

    source = models.ForeignKey(Source)
    url = models.URLField(verify_exists=False)
    text = models.TextField()
    created_on = models.DateTimeField(editable=False)
    retrieved_on = models.DateTimeField(editable=False,
            auto_now_add=True)

    class Meta:
        verbose_name_plural = 'Entries'
        ordering = ['-created_on']

    def __unicode__(self):
        return u"From %s on %s"%(self.source,
                self.retrieved_on.strftime('%d %b %y @ %H:%M:%S'))

Now to go through that model field by field:

source - a foreign key connecting this entry to its parent source.

url - a URL field link to the entry from the source. Notice the verify_exists is manually set to False, if not this could cause some serious performance issues when your stream is being updated with a lot of entries.

text - this is the generic TextField we will use to ...

Django Lifestream part 1

Jan. 16, 2010

A Lifestream is an aggregation of publicly available information pertaining to a person. These streams come from various sources, mainly from social media. You see social media is built off of Web 2.0 and the core tennants of Web 2.0 are (according to Wikipedia):

  • information sharing
  • interoperability
  • user-centered design

These concepts drive social media companies to release APIs. Some of these can be pretty complex like the Facebook Platform. Facebook has tons of resources and documentation. Their platform was launched in 2007 and by 2008 there were 33,000 applications (SFGate via Wikipedia).

Happily, you don't need to learn the ins and outs of every API to reap the benefits of a social media driven world. Most of the major social networks (Facebook, Twitter, etc.) make various pieces of your information available via RSS or Atom feeds. Yes, the old standby...tried and true, old school way of sharing information on the Web.

There are some people who think that the rise of instant social media like Twitter means the death of RSS. I disagree. There has to be some standard way of sharing information. Right now, I feel RSS/Atom is the way to go.

So ...

Death By Typo: 2

Sept. 26, 2009

tagged: | comments

I've been trying to figure out why memcached wasn't working for almost a month! I've used the Ubuntu libraries, I've built from scratch...I was about to recreate the whole server.

Then I found a Google group post that suggested checking the CACHE_BACKEND settings

This is what I had:

CACHE_BACKEND = 'memcached://127.0.0.1:112211/'

Can you spot it? I had an extra freaking 2 in there. Should be:

CACHE_BACKEND = 'memcached://127.0.0.1:11211/'

Crap...problem solved.

Jinja2 and Django's Render to Response

Aug. 31, 2009

**edit, fixed broken link to jinja_r2r

If you haven't figured it out by now, I'm on a big Django kick lately. One of my favorite things about Django is it's loose coupling.

The various layers of the framework shouldn’t “know” about each other unless absolutely necessary.

Django Design Philosophies

This means if we want to use a different templating engine...we can! Why would I want to to such a thing? Honestly, I like the Django templating system just fine, but I'd like some more flexibility. For this my pick is Jinja2. For an overview of the benefits of Jinja vs. Django take a look at Why Jinja is not Django an Why Django Should Have a Look at It.

One major caveat: templates designed for Django are not compatible with Jinja2. You will have to modify existing templates if you want to change the templating engine. You can see Convert Django Templates to Jinja2 for more information on this.

While I was planning my switch to Jinja2 I scoured the Internet for the easiest way to accomplish this. I'm very, very lazy. It seems as if the easiest way to do this is ...

Django Comment Moderation with Akismet

Aug. 21, 2009

Spam sucks. Every comment enabled web application has to deal with spam effectively. I believe spam fighting is an uphill battle, spam is easy to create in massive numbers. I also believe that when it comes to fighting spam you need some serious muscle. This is where Akismet comes in. Akismet does only one thing, and it does it well; it identifies spam. Check out the stats page. Akismet is attractive because of it's strength, it's fancy API, and it's cost (free).

With my rant completed, let's get into the meat and potatoes.

Django's comment add-on has improved in Django 1.0. Among other things, it now comes with:

a generic, extensible comment-moderation system which can be applied to any model or set of models which want to make use of Django’s comment system.

Django Generic Comment Moderation Docs

How cool is that?! Granted, I didn't actually implement this on my blog because I'm still working on getting it to work with Jinja instead of Django's templating system. I did however experiment with it.

Let's start with a comment enabled Post model.

class Post(models.Model):
    author = models.ForeignKey(User ...

So Much For Assuming

Aug. 12, 2009

You know what happens when you assume?

This is the third-ish time I've re-done this blog. I started a few years ago with DreamHost using WordPress. Dreamhost was great, so was Wordpress, it wasn't them...it was me.

The curse of geekdom is never being able to leave well enough alone. We always want to do it better...some call it the hard way, but really it's not...right? I decided to write my own blogging application. I had done some PHP and I figured it'd be fun. I started with CakePHP and really enjoyed it. Then I decided, once again, there's got to be a cooler way. Enter Django. Django was my first experience with the Python programming language. It was love at first site. Yes, that's a pun for anyone paying attention.

The problem with Python web development, as I soon found out, is that it requires more configuration than a lot of shared hosting companies provide. Dreamhost has a couple of wiki pages on Python, even one or two on Django. I could never get it to work, and as always, when a geek can't get something to work, it ...

hello world

Aug. 11, 2009

tagged: | comments

Hello World