'Validate that ordering refers to existing fields or is random.'

def validate_ordering(self, cls, model):

    if cls.ordering:
        check_isseq(cls, 'ordering', cls.ordering)
        for (idx, field) in enumerate(cls.ordering):
            if ((field == '?') and (len(cls.ordering) != 1)):
                raise ImproperlyConfigured(("'%s.ordering'    has    the    random    ordering    marker    '?',    but    contains    other    fields    as    well.    Please    either    remove    '?'    or    the    other    fields." % cls.__name__))
            if (field == '?'):
                continue
            if field.startswith('-'):
                field = field[1:]
            if ('__' in field):
                continue
            get_field(cls, model, ('ordering[%d]' % idx), field)
