def _unique_combinations(model, ignore_pk=False):
    """
    Returns an iterable of iterables to represent all the unique constraints
    defined on the model. For example given the following model definition:

        class ExampleModel(models.Model):
            username = models.CharField(unique=True)
            email = models.EmailField(primary_key=True)
            first_name = models.CharField()
            second_name = models.CharField()

        class Meta:
            unique_together = ('first_name', 'second_name')

    This method would return

    [
        ['username'], # from field level unique=True
        ['email'], # implicit unique constraint from primary_key=True
        ['first_name', 'second_name'] # from model meta unique_together
    ]

    Fields with unique constraint defined in a concrete parent model are ingored
    since they're checked when that model is saved
    """
    # first grab all the unique together constraints
    unique_constraints = [list(together_constraint) for together_constraint in model._meta.unique_together]

    # then the column level constraints - special casing PK if required
    for field in model._meta.fields:
        if field.primary_key and ignore_pk:
            continue

        if field.unique and field.model == model:
            unique_constraints.append([field.name])

    # the caller should sort each inner iterable really - but we do this here
    # for now - motive being that interpolated keys from these values are consistent
    return [sorted(constraint) for constraint in unique_constraints]