Using Django Database Routers With Raw SQL

This is just a little something I ran into and figured maybe others would run into it as well.

If you work much with Django, you may occasionally need to drop down into raw SQL. That works well using the connections __getitem__():

cursor = connections['my_database_2'].cursor()

That works, but it bypasses the router which is obviously a bad idea. Even if you use some sort of model meta-data to decide which database to connect to, changing the router or running tests can cause a headache. Therefore, the way I've started setting this up is:

from django.db import router
cursor = connections[router.get_db_for_read(MyModel)].cursor()

You can change read to write, if needed, but you want to pass a model that uses the database that you want to connect to.

Replies / add new reply

What is the value of four hundred minus one?

Bringing Talent To Nashville: Swag's Not The Answer

This post is in response to a recent post by Nashville's venerable Dave Delaney (founder of Geek Breakfast, et al). In his post, Dave proposes that Nashville creates a position of "Technology Ambassador" to promote the community we have here in Nashville to a wider audience.

I can only speak from my experience, but when my family relocated from NYC to Nashville in 2009, it wasn't swag-bearing social media experts that convinced me to to do so. In fact, I'm pretty sure if I had been assaulted by an over-eager ambassador at a conference with branded tote-bags, lapel buttons, and t-shirts, I would have written it off as a middle America city that was simply trying much too hard.

When I was deciding where to relocate the criteria came down to three basic questions:

  • What is the quality of life like in the community? (Is traffic horrific? Do people bike to work?)
  • What is the cost of living and the average salary for someone with my level of experience?
  • What does the tech community look like (language user groups, book discussions)?

The first two are obviously much more important. I didn't want to live in Atlanta and deal with it’s horrific traffic. I didn’t move to North Carolina because I wanted to live in a state with a low cost of living. Both of those cities pay more, on average, for developers, but the deciding factor for me was quality of life.

As for the third criteria, Nashville has a handful of high-level "technologist" functions (NTC, Digital Nashville, Geek Breakfast), but more importantly, it also has a contingent of more in-depth user groups (Nashville PHP, Nashville Dynamic Languages, .NET Nashville, Arduino Nashville, and many, many others). Those are important, and any city worth its digital salt needs those groups to grow.

Geek Breakfast, in particular, was instrumental in getting me connected to the larger tech community. Through it I found out about the Centresource Mixer. There I met Nicholas Holland, from whom I rented office space to continue plying my trade. While working there, I met Jason Moore (a fellow tenant), who talked me into joining him in a new venture in the healthcare sector. That company recently "graduated" from the Entrepreneur Center downtown, received funding, and is now chugging along full steam.

The fact that in two years I could go from a Nashville newbie to company co-founder is a testament to the vibrant community here.

It wasn’t marketers bearing swag.

If we really want to make Nashville a more attractive city to smart, talented, and creative people, we need to focus our efforts on increasing the quality of life. We need to elect representatives who are more focused on improving our city’s infrastructure, not criminalizing the sharing of Netflix passwords. We need to elect leaders who care about reducing pedestrian deaths, or increasing awareness of public transit, not leaders who are preoccupied with publication of images that might offend someone. Our fair city has less green space than the average city of comparable size. It’s mass transit is unreliable. It tops the list of cities in both pedestrian deaths and forcible rapes. [Source]

It would take a mountain of swag to overcome the provincial, xenophobic sort of legislation for which our state makes national news.

Instead of passing our city off as something it isn’t (it is not Silicon Alley and it never will be Silicon Alley - for some people this is a good thing), we should acknowledge its warts, appreciate its advantages and sense of community, and work on changing the parochial politics and increasing the city’s quality of life.

Replies / add new reply

What is the value of four hundred minus one?

by Pinky Gonzales
06/17/2011 09:14

This is one of the most succinct and insightful blog posts I have ever read. You nailed it, Brian.

I have lived in Nashville for 11 years, helped to build a well-known tech company, employed nearly 100 people at various times, and consulted with numerous startups and entrepreneurs, and I believe ALL of them would agree with your sentiment. Nashville is a beautiful city full of great people with a diverse set of talents. While it would be nice to have more people with tech skills, big cities have other problems we are blessed to be without. Life is a balance.

Bravo, good sir. You're an asset to this fine city.


by Michael Burcham
06/17/2011 09:15

Loved this post, Brian. So true.


by mark montgomery
06/17/2011 11:02

I'd echo both these gents, well said (and you are working with a great company, your partner is one of my favs)

what I would add/ask, is quite simple. in the absence of a swaggy ambassador, how do we get the word out to the world that Nashville is so much more than heehaw and healthcare?

if we do not address this, all the juice that we are creating will not have the peeps necessary to actually take all that entrepreneurial energy and put it into practice!


by Charles Alexander
06/17/2011 11:38

Brian,

this is a great post. I think every politician and old school holdover in Nash/TN needs to read this.

Speaking as a family guy, I think schools & transportation should be a #1 priority. As a minority, I think all this wasted energy on making people feel marginalized is just that...wasted...

Bravo, dear sir.

Charles


by Chris Ennis
06/17/2011 11:46

Great post...

To Mark's point, I wrote numerous times while I lived in Nashville for the need to have an event that positioned the tech industry radar squarely on the community for a week. My perception of Austin changed significantly after I attended my first SXSW. I don't think you can change the perception without bringing people in to visit. Once people visit, so many walk away with their perceptions significantly altered.

I love Nashville and miss it, but the next Silicon alley/valley it will never be. It will never be Austin. It will never be Boulder. And that's ok. What is has got to be is a community that knows its strengths and plays off of them.

And yes, the rest of the country laughs at Tennessee and some of its asinine legislation, but even with that, you bring people in and share with them a little bit of Nashville and they'll be sold.


by Dave Delaney
06/17/2011 04:37

Great post Brian. I'm glad you took the ball and ran with it. You raise great points that I agree with fully.

I should mention that I am not talking about a swag-carrying clown to scream about Nashville. I'm talking about what many of us already do, aside from our regular jobs.

When we attend conferences, we naturally talk to attendees about how wonderful Nashville and our community is. Of course it's not Nashville you should be selling first though, it's the business that put you at the conference in the first place.

I'm talking about a person who is hired to represent our city. One who would go and passively promote Nashville, but certainly not hand out swag. If someone expressed interest in finding out more about Nashville, it would only be then that you would discreetly hand out a business card. It would be up to that person to carry on the conversation later, just as you would after meeting any business contact at a conference.

I just wanted to be sure that my idea isn't misunderstood.

Thanks again Brian! See you at breakfast.


by Brian
06/21/2011 07:00

Perhaps the "swag" is the result of a bit of hyperbole on my part, if that's not your intent then perhaps I overdid it.

Would you trust someone who was hired to promote a city's advantages over someone who has either lived there or still lives there? I still think that a hired promoter would have very little impact on decisions to move here, or awareness of Nashville's friendly tech community.


On Entrepreneurship in Nashville

I finally got around to listening to the Nashville Feed podcast on Entrepreneurship in Nashville. It's worth listening to if you live in a middle-America city and you're a web worker.

Both Marcus Whitney and Chris Ennis addressed issues that they see facing the area: chief among them is lack of talent. Chris pointed out that there are a lot of talented developers working in healthcare. Marcus complained about local developers not having an "entrepreneurial streak" - they are happy, he says, working their day jobs and they're not really that interested in doing something new or risky.


Make something happen...

Part of this is probably true. However, I believe Chris and Marcus are a little too eager to lay blame at the feet of developers.

Why do developers in Nashville seem more interested in steady work?

Family Time. This is built into the area culture. Nashville is a family-friendly city (that's one reason I live here). Many of the developers here have families, so they're quite happy to take the 9-5 gig. That allows (most of) them to have evenings and weekends with their families, free of the fetters of the startup frantic to be the first to reach market. Startups generally require a lot more hours of work up front.

Steady Pay. Startups aren't known for their steady pay. In a city like Nashville, where venture capital money is hard to come by, most startups are based on sweat-equity. If you've got a family, it's quite difficult to go for a two or three month stretch without any pay at all.

Higher Pay. This is true up front, at least. From what I've seen of the Nashville market, pay for developers is pretty miserly. Most startups fail to recognize the exponential difference between a good developer and a newbie (as Marcus mentioned in the podcast), so they look at the vast difference in pricing ($25-$125 an hour) and, not knowing any better, go with the cheaper option. That's great for the developer just getting started, but it's bad for the high-caliber talent.

One of the primary gripes that I have with the Nashville area (and this is true of middle America in general, I think) is that there is very little appreciation for development talent. The "idea guys" see the developers as something akin to accountants: the "idea" is worth a million dollars (in reality, it's worthless), and the developers is just the wheel cog that they can plug in to make it happen. They do not value execution, and therefore they see no reason to appreciate the guys that are, ultimately, responsible for building a product.

As long as developers are just considered "cogs in the wheels", Nashville won't ever see a strong entrepreneurial development community. High-caliber developers will continue to either move elsewhere, or, as I have been doing for the past year, work remotely for companies based elsewhere. Developers who are willing to take on the additional risk of working with a startup generally want to be seen as valued partners (this is true in cases of sweat equity or just straight-up payment).

I honestly wish I had more opportunities to work with local startups. I miss the collaborative atmosphere that I was able to be a part of in NYC. I don't think you can replicate that with remote workers. But the only gigs here that I'm interested in are the ones that take development (read: execution) seriously.

Most of the other points that Marcus and Chris made in the podcast are absolutely correct. I do wish that they had discussed more issues that are relevant specifically to Nashville; you could have swapped out "Nashville" for a number of middle America cities of the same size and many of the same points would still have been applicable.

Replies / add new reply

What is the value of four hundred minus one?

by Josh Crews
06/8/2010 12:52

I haven't listened to this yet, but I want to now after the post.

On the non-discernment of developer talent/value; what do we do different?


by Brian D.
06/8/2010 04:32

I'm not aware of a really good answer for that. Non-technical people have very little ability to select talent. The best solution is to find someone that *is* technical that can help you vet developers.

I've written another article in the past on tips for finding good freelance developers.

http://realm3.com/articles/tips_for_finding_great_freelance_developers

Joel Spolsky has a good post on the same topic.

http://www.joelonsoftware.com/articles/FindingGreatDevelopers.html


by David Beronja
08/25/2010 10:09

I have been meaning to comment for a while sorry for the delay. Thanks for the post and listening to the show. We are planning a podcast this fall continuing with the topic. I think getting developers on as well as the idea guys would be a good mix. Again thanks for the ideas and I hope you continue to listen.


Readit.me

A typical library trip.

Every developer has a different method for learning a new language. Some learn by reading tutorials, others by reading code, others by writing it; most learn by some unique combination of these things. I tend to gravitate towards the "writing it" angle. I can read a book or a blog post, but unless I actually create something, I do not retain the knowledge for very long. When I first learned CakePHP, I did it by writing an application called "Spitgamer."

For my first full-scale Rails app, I decided to create an application that is a minimalistic reading diary. I read a lot of library books and I often find myself checking out the same book again, attempting to remember if I read it, and if so, what I thought about it. I've checked out some of the other online reader communities, but they seemed to suffer from feature-bloat. I like minimal interfaces (ala delicious).

Readit.me still lacks some of the ideas that I'd like to see deployed, but it's basic premise is all there. (I am an adherent of the school of release early, release often.) I used the Amazon e-commerce API to pull in book data. It's currently tied into Facebook Connect, and I hope to integrate it with other social services as I have time.

It's been a good experience working with Rails, too. I prefer it's reliance on the command-line, as that's where I'm most comfortable.

It's difficult to make the jump from a "PHP" guy to a "Rails/Python" guy. My work comes from referrals - so that tends to mean that all my past PHP clients forward me new PHP work. Picking up work in a new language can be difficult as a consultant. However, I'm certainly headed in that direction and I hope to eventually phase out the PHP work into "occasional" projects and maintaining legacy applications (much as I work with Java now).

Replies / add new reply

What is the value of four hundred minus one?

Ongoing Compendium of Nashville User Groups

There are a lot of programming language or web application user groups here in Nashville. I live and breath open-source, so a lot of the groups I am aware of tend to be OS-centric. There have been many complaints that there is no one-stop-shop for anyone looking for these groups (or an event calendar for the Nashville tech scene in general). NashvilleGeeks.org has been working on a calendar for the tech-scene in general, but it's still a work in progress.

Here's the list, last updated May 26, 2010.

Nashville PHP
Appears to have been resurrected by Ben Ramsey, formerly an active contributor to the Atlanta PHP UG, recently relocated to Nashville and working at Moontoast. Per Ramsey's Rebooting Nashville PHP blog post:
"Nashville PHP will hold regular monthly meetings on the second Tuesday of every month at 7pm at the same location each month. I am currently solidifying this location, and I’ll let you know when details are finalized."
PyNash
Nashville's Python user group meets at Emma on a monthly basis.
Nashville Ruby on Rails Meetup
Run by the venerable Josh Crews. Meets once a month at Centresource, I believe on the second-to-last Thursday of the month (the odd date is due to calendar conflicts with other CS events) at 5:30pm.
Nashville Drupalers
Not sure who is running this one (I'm not a Drupal guy), but they appear to have regularly scheduled meetings.
Nashville Symfony UG
Run by Travis Roberts, Brent Schaffer, and Ryan Weaver. Meets at 6pm the first Tuesday of the month at Centresource.
Nashville Dynamic Languages
You'll have more luck with this group on IRC (#nashdl, Freenode). They meet weekly for hack sessions and socialization, but it's a pretty small group and seems to function as more of a social club than an actual user group.
Nashville Linux Users Group
Also on IRC (#nlug, Freenode). Meets at 6pm on the second Tuesday of every month on the Vanderbilt campus.

Groups That Appear Inactive

Enterprise LAMP
Updated May 25, 2010: Appears to now be completely defunct. I suspect this was more about promoting the Enterprise LAMP conference in late 2009, rather than an active ongoing group.
Run by Marcus Whitney. Unfortunately the website has very little information on the monthly meetups, and I'm not sure there is a site with current information on it. The best way to find out about it is to follow enterpriselamp on Twitter. This group generally covers a wide range of topics in the open source world. It meets monthly and alternates between Emma in Nashville and Vaco Technology in Brentwood. There is also an email list, Nashville OSS, and and upcoming site (nashvilleoss.org) meant to help folks keep up with all of the local UGs.
Nashville Ruby Group
May 2010 - Email group still somewhat active, but I haven't noticed any meetings lately. Appears to be somewhat dormant.
Run by Will Bridges. Not sure what the regular meetup schedule is yet.

Am I missing anyone? Let me know in the comments or shoot me an email.

Replies / add new reply

What is the value of four hundred minus one?

by Shawn Stratton
10/27/2009 09:11

Clark Everett and I have talked about restarting the Nashville PUG. Need some show of interest though.


by Brian
10/27/2009 09:36

I would certainly be interested. I'd like to see a group that has some staying power rather than wilting away after a few months.


by Brent Shaffer
05/26/2010 09:44

The Symfony Meetup is co-run by Ryan Weaver of iostudio as well (weaverryan@gmail.com)


by Brian D.
05/27/2010 09:54

Duly noted, thanks!