Django: ProgrammingError: Can’t Adapt
I find I get an error like this far too often, but not often enough to remember why I got the problem the previous time. For my own sanity, I'm blogging about it for reference. The error itself is not very descriptive:
Exception Type: ProgrammingError
Exception Value: can't adapt
Unless there is something I'm forgetting, it seems 100% of the time it has been a simple error. I use the get_or_create function to retrieve a model, but I don't account for the "created" variable. So then I try to use the tuple as a model object somewhere and it throws this error.
For example, here is the wrong way:
person = Person.objects.get_or_create(first_name="Dustin", last_name="Davis") print person.first_name
And now for the correction:
person, created = Person.objects.get_or_create(first_name="Dustin", last_name="Davis") print person.first_name
January 28, 2010
Tags: django Posted in: Programming & Internet
5 Comments
Basic Authentication on mod_wsgi
I'm currently in the process of creating an iPhone app for Inzolo. This requires an API of course. I wanted to take advantage of what was currently available for Django and I came across wapi. Time is of the essence so I decided to take the easiest route and use basic authentication for now. (I'm still learning about API best practices).
I got some basic API calls working in my local machine running "manage.py runserver". Once I pushed it live, the basic authentication would not work. I'm hosting with Webfaction so I posted to the forum for help and continued to look.
I wasn't making progress at all so I started looking for another API framework and learned of Piston. In hindsight I would have started here because it was developed by bitbucket.org and it seems it will have much longer longevity.
In any case, while reading the docs for Piston I saw this note:
Note: that using
piston.authentication.HttpBasicAuthenticationwith apache and mod_wsgi requires you to add theWSGIPassAuthorization Ondirective to the server or vhost config, otherwise django-piston cannot read the authentication data fromHTTP_AUTHORIZATIONinrequest.META. See: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPassAuthorization.
That was the clue I needed! I added this one-liner to apache config and... still didn't work.
I then went through the process of upgrading. I was running Django (1.0.2)/mod_wsgi (2.0)/Python (2.5), I upgraded to Django (1.1.1)/mod_wsgi (2.5)/Python (2.5). Now, with the "WSGIPassAuthorization On" it works.
January 11, 2010
Tags: api, authentication, basic auth, djanog, mod_wsgi, piston, wapi, webfaction, wsgi Posted in: Programming & Internet
10 Comments
Fixing IE Issues
This morning for whatever reason I was loathing IE. I hadn’t done any development work all weekend so I don’t even know why it was on my mind. In any case I had an epiphany of sorts.
Despite being totally proprietary, IE seems to be the most easily exploited browser due to its support of active x. (It’s no coincidence that IE users suffer from the most viruses, but that is neither here nor there). What if someone were to hack IE and make use of the popular open source rendering engine webkit?
So instead of the ugly display because IE still can’t do CSS rounded corners and other goodies, and instead of lame javascript errors, IE could finally work!
Surely I’m not the smartest guy on the planet. Someone had to have thought of this already. But would that person spend the time to make it happen?
Sure they would… if they worked for Google.
I was delighted to find Google Chrome Frame. It
I tried it out on a particular site I was working on. I have never seen IE render so beautifully!
Thanks Google for making IE suck less!
December 15, 2009
Tags: Chrome, Google, IE Posted in: Programming & Internet, Technology
26 Comments
Copy Model Object in Django
I ran into a situation where I wanted to created a new database record from an existing record (model object). I figured there should be a fairly simple solution. It turns out there is and I want to thank Seveas on IRC #django for pointing it out for me. This is essentially what I did:
from copy import deepcopy
old_obj = deepcopy(obj)
old_obj.id = None
old_obj.save()
Voila!
November 5, 2009
Tags: django Posted in: Programming & Internet
17 Comments
Why The Cash Envelope System Didn’t Work for Us
Now let me preface this by saying I am a huge fan of Dave Ramsey and I see the wisdom in all of his teachings. Now that said, I readily admit I don't follow everything he says. One area in which I don't follow along is with the cash envelope budget system.
I think the system is excellent. I do believe it "hurts" more to spend cash. It is hard for me to break a $20. I like that fact that when I spend cash I usually end up with change that becomes savings because I never spend change (I don't know that Dave ever mentions that one, but it is a nice bonus).
My wife and I tried the cash envelope system. We gave up after only two months. Here are the reasons why:
- Inconvenience. Let's face it, debit cards make life so much more convenient. It is not convenient to got to the bank or ATM once or twice a month to allocate cash in your envelopes. I hate waiting in line at the bank so I avoid it at all costs.
- Inconvenience. Yeah, same reason, but different. It is inconvenient to pay with cash. Grocery stores are not so bad really - unless you use the self-checkout, which I often do - again, because there is usually no lines there. Putting cash in those machines is downright painful. And really, who pays for gasoline with cash anymore?
- Location of the envelope. It's happened on more than one occasion that my wife is making dinner and finds she is missing an ingredient. So what does she do? She calls me and asks that I pick it up on the way home from work. If I don't have enough blow money in my wallet I reach for the debit card.
- Have you ever reached the checkout and when it is time to pay you realize you don't have your wallet. That is really mortifying to me. I'm frantic in that case. I start looking through my car for a hidden $100 bill (it's never there) or a blank check (never there either). Even if I only live 3 blocks away it is inconvenient and super embarrassing. If you forget your envelope and you don't realize it before you get in line to checkout, are you really going to go home and get it? Not me, I'll pull out the debit card again. Of course my intention is to go back to the bank and deposit the amount of cash I spent, but I don't because that is so... inconvenient!
- While it "hurts" me to spend cash, it seems to have the opposite effect on my wife. If money talks, all it ever says to my wife is "goodbye". I'm not being rude here. She readily admits this. It's not more difficult for my dear wife to spend cash than it is to spend money in any other way. Basically, it is just more (there it is again) inconvenient.
Let's face it. I love debit cards. What I like about them is that if you use your debit card as a debit card (as opposed to credit card) it withdraws the cash out of your account immediately. Your bank account balance is updated immediately (at least where I bank it is).
Here are some more things I love about my debit card:
- It is free to use. I have a free checking account. I don't have to pay for new checks as long as I use my debit card.
- My bank let's me customize it. I generally put pictures of my kids on it so people can tell me how cute they are. I sometimes wonder though if my bank would be opposed to me scanning in my drivers license so people don't have to ask for it when I use my debit card in place of a credit card.
- It's thin. With all that cash, your wallet can become a pain in the butt - literally.
- It doubles as a credit card. For those places that don't accept debit cards but can take credit cards, my debit card works fine. I generally have to wait a day or two for the transaction to appear on my bank statement though.
- Did I mention it is convenient?
So, how do we make use of the timeless & effective envelope budget system with debit cards? We use Inzolo.
Whenever I get income, be it a paycheck or any other form of income, I decide where we are going to spend that money and allocate it to a virtual envelope.
Whenever we spend money using our debit card, the transaction imported lightning fast into Inzolo and I specify what envelope that money came out of. I can visually see all my envelope balances. If I go over in an envelope I can easily move the exact amount I need to cover the difference from another envelope.
It's basically like haveing dozens of savings accounts set up in your bank and deciding where each transaction will come out of. I can even split transactions so that different portions come out of different envelopes.
So if you love the idea of the cash envelope system, but don't feel you have the will power to stick to it, I urge you to give Inzolo a try.

October 20, 2009
Tags: budget, budgeting, cash, envelope budget, envelope method Posted in: Family, Finance, Web Sites
31 Comments
IE & JSON Caching Bug
I came across a weird bug. It seems that IE is the only browser that has a tendency insists on caching JSON results. I created a little api call that returned a list of users “favorites”. I use jQuery to retrieve this list and make updates to my site.
Well apparently IE caches the JSON file, so any changes are not reflected. Firefox and Safari seem to work fine. I tried a number of mime types (as I understand it, the defacto standard is application/json), but the only one that seemed to keep IE from caching it was text/plain. Go figure. And people wonder why developers hate IE so much…
September 17, 2009
Tags: cache, IE, jquery, json Posted in: Programming & Internet
23 Comments
Django cron on Webfaction
James Bennett addresses one of the most frequently asked questions in Django – "How do I write a standalone script which makes use of Django components?"
That is what I needed to do. I'm still learning Python so I wasn't sure why the methods he described in his article didn't work for me. (OK, I have an idea, but for the fear of looking stupid I'm not going to try to explain it.)
I'm using Webfaction to host my site, so I turned to their forum for assistance and found this topic. Still the examples didn't quite work for me either. Finally I found a clue in my WSGI script. Adding the following lines to my python file is what I needed to get me going:
import sys, os
sys.path = ['/home/mylogin/webapps/mysite, '/home/mylogin/webapps/mysite/lib/python2.5'] + sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
July 31, 2009
Tags: cron, django, python, webfaction Posted in: Programming & Internet
11 Comments
Use Google Earth to Track Your Mileage
Recently I've taken up hiking during lunch. There is a nice mountain trail behind my house the I really enjoy. There are a few landmarks that I generally try to make it to with the time I have available. I was curious exactly how far those landmarks were so I used Google Earth to find out. Curious to know just how accurate Google Earth was, I decided to test it out. I found a local high school track and measured the path around it. .25 miles looks accurate to me!
To use this tool, click the ruler icon and use the path tab to draw polygon shapes.
July 8, 2009
Tags: google earth Posted in: Technology
53 Comments
Windows 7 Releases October 22nd 2009
This morning was the first time I heard an official release date for Windows 7. I've been running Windows 7 betas for the past 3 months and it has been far more stable and responsive than Vista was for me. I will definitely be upgrading this one on release day! I have just put in my pre-order at Amazon. I'll be going with the Ultimate version ($219) since I have a media center PC and I want all the bells and whistles. Really, this is the first time EVER I've been excited for a Microsoft launch. Crazy.
June 26, 2009
Tags: windows 7 Posted in: Products, Technology
43 Comments
Comcast is My Friend Today
So this is something I have known about and have done in the past, and I kept meaning to do it, but today I finally did it. I lowered my cable/internet bill.
Truthfully I was considering cancelling cable anyway. I'm paying about $117 per month for high speed internet and basic digital cable. I should note that I am paying $10 extra for higher speed internet and getting a $10 discount for bundling cable and internet so that is pretty much a wash.
Since I don't watch a lot of TV I wasn't too concerned with cancelling it altogether. I know my wife enjoys watching Fox News in the mornings and watching TLC and HGTV during the day as she is folding clothes and stuff. For the kids we have a few shows we DVR for them like Tom & Jerry and Martha Speaks. So when they want to watch TV we generally have something available.
Since I have built my own media center pc, we have the benefit of watching shows online. I recently discovered hulu desktop which makes it even easier. So that being said I was totally ready to just cancel cable altogether. I guess the biggest sacrifice would be from my wife who, like I said, enjoys Fox News and TLC. One other downside that I would miss is being able to see the 500 or so movies that will be playing soon on all our channels and recording the ones I want to see. I think this is one of the coolest features of Windows Media Center.
So I determined to call and cancel and figured that Comcast would offer me a deal to get me to stay. If the deal was good enough I would take it. Before calling I read some great tips from Matt Jabs that helped me stay upbeat and friendly with the customer support person.
I was connected with "April" and the conversation went something like this:
Me: Hi, I currently have cable and internet and I would like to cancel my cable TV service only.
April: [Gets my name and retrieves account] OK, do you mind if I ask why you want to cancel?
Me: I just want to lower my bill.
April: OK, well, how about I see if I can lower you bill. It appears you are currently paying $117… per month, is that right?
Me: Yeah, that sounds right.
April: It looks like you are paying $10 extra for an 8 megabit connection. I can remove that $10 charge for a year. For your cable service, I can reduce the price to $29 per month for a year. Would that work for you?
Me: So what would be my total bill?
April: It would be $71 per month, saving you $46 dollars per month.
Me: Wow, for a year huh? Yes, let's do that.
April: OK, you're all set.
Me: Really, that's all I have to do?
April: Yep.
Me: Great! Thank you very much.
April: No problem. Thank you for being a Comcast customer.
So I spent a total of 3 minutes and 45 seconds on the phone and saved myself $552 over the course of the year. I would say that was worth my time and I don't mind keeping cable TV around either. Especially now that I have a big screen to watch BYU & Utah football games this fall! Oh, did I forget to mention that?
June 24, 2009
Tags: bills, cable, comcast, internet, TV Posted in: Finance
14 Comments



