Yeah that all is a bit messy. I copied it over from cydns/models.py