def _has_unique_constraints(model_or_instance):
    """
    Returns a boolean to indicate if the given model has any type of unique
    constraint defined (e.g. unique on a single field, or meta.unique_together).

    To support concrete model inheritance we state that uniqueness checks
    should only be performed on the class that the defines the unique constraint.

    Note - you can see a much more verbose implementation of this in
    django.db.models.base.Model._get_unique_checks() - but we implement our
    own logic to exit early when the first constraint is found.
    """
    meta_options = model_or_instance._meta
    # we may get an instance here, so ensure we have a reference to the
    # model class
    model_class = meta_options.model
    unique_together = meta_options.unique_together
    unique_fields = any(
        field.unique and field.model == model_class
        for field in meta_options.fields
    )

    return any([unique_fields, unique_together])