'Given a model, return a ModelState representing it.'

@classmethod
def from_model(cls, model, exclude_rels=False):

    fields = []
    for field in model._meta.local_fields:
        if (getattr(field, 'remote_field', None) and exclude_rels):
            continue
        if isinstance(field, OrderWrt):
            continue
        name = field.name
        try:
            fields.append((name, field.clone()))
        except TypeError as e:
            raise TypeError(("Couldn't    reconstruct    field    %s    on    %s:    %s" % (name, model._meta.label, e)))
    if (not exclude_rels):
        for field in model._meta.local_many_to_many:
            name = field.name
            try:
                fields.append((name, field.clone()))
            except TypeError as e:
                raise TypeError(("Couldn't    reconstruct    m2m    field    %s    on    %s:    %s" % (name, model._meta.object_name, e)))
    options = {}
    for name in DEFAULT_NAMES:
        if (name in ['apps', 'app_label']):
            continue
        elif (name in model._meta.original_attrs):
            if (name == 'unique_together'):
                ut = model._meta.original_attrs['unique_together']
                options[name] = set(normalize_together(ut))
            elif (name == 'index_together'):
                it = model._meta.original_attrs['index_together']
                options[name] = set(normalize_together(it))
            elif (name == 'indexes'):
                indexes = [idx.clone() for idx in model._meta.indexes]
                for index in indexes:
                    if (not index.name):
                        index.set_name_with_model(model)
                options['indexes'] = indexes
            else:
                options[name] = model._meta.original_attrs[name]
    if exclude_rels:
        for key in ['unique_together', 'index_together', 'order_with_respect_to']:
            if (key in options):
                del options[key]
    elif (options.get('order_with_respect_to') in {field.name for field in model._meta.private_fields}):
        del options['order_with_respect_to']
    def flatten_bases(model):
        bases = []
        for base in model.__bases__:
            if (hasattr(base, '_meta') and base._meta.abstract):
                bases.extend(flatten_bases(base))
            else:
                bases.append(base)
        return bases
    flattened_bases = sorted(set(flatten_bases(model)), key=(lambda x: model.__mro__.index(x)))
    bases = tuple(((base._meta.label_lower if hasattr(base, '_meta') else base) for base in flattened_bases))
    if (not any(((isinstance(base, str) or issubclass(base, models.Model)) for base in bases))):
        bases = (models.Model,)
    managers = []
    manager_names = set()
    default_manager_shim = None
    for manager in model._meta.managers:
        if (manager.name in manager_names):
            continue
        elif manager.use_in_migrations:
            new_manager = copy.copy(manager)
            new_manager._set_creation_counter()
        elif ((manager is model._base_manager) or (manager is model._default_manager)):
            new_manager = models.Manager()
            new_manager.model = manager.model
            new_manager.name = manager.name
            if (manager is model._default_manager):
                default_manager_shim = new_manager
        else:
            continue
        manager_names.add(manager.name)
        managers.append((manager.name, new_manager))
    if (managers == [('objects', default_manager_shim)]):
        managers = []
    return cls(model._meta.app_label, model._meta.object_name, fields, options, bases, managers)
