Django 1.5 foreign key dependency

Also make sure that code doesn't call compat.py twice.
This ensures there's no circular dependencies.