class django_choices(tuple):
    '''
    Creates a choices data type like what django needs for models. 
    '''
    def __new__(self, *args, **kwargs):
        self.choices = []
        if kwargs:
          for val in kwargs.values():
              for key in kwargs.keys():
                if kwargs[key] == val:
                  self.choices.append((val, key))
        return tuple.__new__(self, self.choices or args)
        
    def to_dict(self):
        '''
        Automatically converts the choices to a dictionary. Useful for type lookups.
        '''
        d = {}
        for choice in self:
            d[choice[1].lower()] = choice[0]
        return d