Validates a class specified as a model admin.

    Right now this means validating prepopulated_fields, as for
    multilingual models DM handles them by itself.

def validate_admin_registration(cls, model):
    """
    Validates a class specified as a model admin.

    Right now this means validating prepopulated_fields, as for
    multilingual models DM handles them by itself.
    """

    if not is_multilingual_model(model):
        return

    from django.contrib.admin.validation import check_isdict, check_isseq

    opts = model._meta

    # this is heavily based on django.contrib.admin.validation.
    if hasattr(cls, '_dm_prepopulated_fields'):
        check_isdict(cls, '_dm_prepopulated_fields', cls.prepopulated_fields)
        for field, val in cls._dm_prepopulated_fields.items():
            f = get_field(cls, model, opts, 'prepopulated_fields', field)
            if isinstance(f, (models.DateTimeField, models.ForeignKey,
                models.ManyToManyField)):
                raise ImproperlyConfigured("'%s.prepopulated_fields['%s']' "
                        "is either a DateTimeField, ForeignKey or "
                        "ManyToManyField. This isn't allowed."
                        % (cls.__name__, field))
            check_isseq(cls, "prepopulated_fields['%s']" % field, val)
            for idx, f in enumerate(val):
                get_field(cls, model,
                        opts, "prepopulated_fields['%s'][%d]"
                        % (f, idx), f)