Archive for May, 2009

Amazon steps up to AppEngine

Thursday, May 28th, 2009

Google’s AppEngine was quite promising from the start.  Automatic scaling and load balancing without having to think about the administrative side is extremely nice.

But that’s about it.  There’s a couple of things which make AppEngine a bit cumbersome to recommend for a new application, all of which are well served by Amazon EC2+ELB+ES:

  1. Lack of SSL for your custom domain
  2. Can’t use many django pluggables out of the box because of RDMS dependencies
  3. Some would say naked domains, but ELB can’t do naked domains either, so this is a wash.
  4. Can’t use other off the shelf software, like wordpress, etc.

Don’t get me wrong, I really like AppEngine, and for small apps I’m going to stick with it because of:

  1. Cost – the free instance can’t be beat.  You’re at an automatic $100/month with EC2.
  2. Little to no infrastructure admin needed – mainly just some DNS.
  3. You can run Django 1.0 with either app-engine-patch, or the django-helper.

django ManyToManyFields and form.save(commit=False)

Tuesday, May 5th, 2009

Those django devs have done a whole lot of thinking, and we’re reaping all the benefits.

Let’s say you have a model with a ManyToManyField in it, but you can’t save the ModelForm outright because you have to set a user into it (or some other foreignkey field).  So you do something like this:


item = form.save(commit=False)
item.user = request.User
item.save()

When you go to test your page, it looks like the ManyToManyFields are not getting saved – and that is because they are not. They are only saved when you save the form object, or manipulate the collections explicitly.

Look here: http://docs.djangoproject.com/en/1.0/topics/forms/modelforms/ and you’ll see there is a nifty function added to the form named save_m2m(). You have to call this explicitly when you save a form (with a ManyToManyField) with commit=False. So you should do this:


item = form.save(commit=False)
item.user = request.user
item.save()
form.save_m2m()