I has a fevr… Django update
Been feeling terrible these last few days, down with the sickness of a fevr (Web 2.0 way of spelling it).
Django has become to me like a beautiful girl who is also a hacker. One in 6.2 billion. Today, I was working on making the database for ClassOwl a lot cleaner and more efficient (for scaling, of course) and I knew I had to use two columns in the database -- one to state the name of the model, and the other for the row ID in that model (table) where I would be pulling the data from. This makes it so I can have one master table that stores all the data, and allows me to create new types of things to be put in people's planners extremely easily.
For example, the three I am using right now are 1) homework 2) tests 3) events. But maybe some day after reader thousands of emails from users we would like to add something like class work as part of it. This would be simple, all I would have to do is create a new model (ClassWork) with all of the fields that are unique to a ClassWork object (time handed out, time due, maybe a discussion board). Doing it the way I have things set up right now, I would have to create a new model called ClassWork which has a lot of duplicate columns that homework/tests/events have, and then I would have to go in and add a bunch of code to my views to make it work. A big pain in the arse :).
Django makes this even simpler with it's Generic Relations. You specify the two columns (they give you a helper called ContentType which is amazing) and then add another line:
content_object = generic.GenericForeignKey()
And vualah! Now you can create a foreign key to any model you want, specify the primary key, and then access it with item.content_object when getting the data out of that row you are fetching. Man it seems like the only way they could make it better is if they started adding tons of "magic" features like they have in Rails... Actually, scratch that, I'm more of a control freak with my code, Django is perfect the way it is.
I LOVE YOU DJANGO.