Rails vs Grails vs Django models

Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails, Grails and Django treats your models. In Django and Grails you can look at a model class and see all the properties it has: [python] class Organization(models.Model): name = models.CharField(max_length=255) url = models.URLField(verify_exists=False) orgtype = models.ForeignKey(OrgType) [/python] The same model class in Rails typically looks like this: [ruby] class Organization < ActiveRecord::Base belongs_to :OrgType end [/ruby]...

June 24, 2009 · Peter Krantz

Integrating Yahoo Search in a Django site in 5 easy steps

I have been experimenting with various search options for the eutveckling.se site for a while. Google Custom Search is nice and very fast, but the number of ads appearing in the search result page makes it difficult for users to separate result items from ads. (Update: I am sticking with Google Custom Search until I figure out how to get Yahoo search to present proper excerpts). I am a fast reader which comes with the tradeoff of missing important information sometimes....

December 18, 2008 · Peter Krantz

Improving Django performance with better caching

The Django cache middleware is great, but has one drawback. If you are caching views (which can give a nice performance boost) Django will only use the path segment of the URL to create a cache key. If you are an avid reader of RFC 3986 you may remember that a URI consists of multiple components; path and query being of special interest here. The problem is documented in ticket 4992 (Update: it is now in Django)....

November 2, 2008 · Peter Krantz

Stuff I learned over the weekend

1. Finding stuff in lists of dicts in Python If you have a list of dicts in Python like this: [python]items = [{“id”:1, “name”: “Rasmus”}, {“id”: 2, “name”: “Rick”}][/python] …and want to check if there are any dict items with an id of a specific value (e.g. 2) I first came up with this: [python]2 in map(lambda x: x[‘id’], items)[/python] The downside is that it will loop all items which may be inefficient for larger lists....

October 27, 2008 · Peter Krantz