'Gather a list of checks to perform. Since validate_unique could be
called from a ModelForm, some fields may have been excluded; we can\'t
perform a unique check on a model that is missing fields involved
in that check.
Fields that did not validate should also be excluded, but they need
to be passed in via the exclude argument.'

def _get_unique_checks(self, exclude=None):

    if (exclude is None):
        exclude = []
    unique_checks = []
    unique_togethers = [(self.__class__, self._meta.unique_together)]
    for parent_class in self._meta.parents.keys():
        if parent_class._meta.unique_together:
            unique_togethers.append((parent_class, parent_class._meta.unique_together))
    for (model_class, unique_together) in unique_togethers:
        for check in unique_together:
            for name in check:
                if (name in exclude):
                    break
            else:
                unique_checks.append((model_class, tuple(check)))
    date_checks = []
    fields_with_class = [(self.__class__, self._meta.local_fields)]
    for parent_class in self._meta.parents.keys():
        fields_with_class.append((parent_class, parent_class._meta.local_fields))
    for (model_class, fields) in fields_with_class:
        for f in fields:
            name = f.name
            if (name in exclude):
                continue
            if f.unique:
                unique_checks.append((model_class, (name,)))
            if (f.unique_for_date and (f.unique_for_date not in exclude)):
                date_checks.append((model_class, 'date', name, f.unique_for_date))
            if (f.unique_for_year and (f.unique_for_year not in exclude)):
                date_checks.append((model_class, 'year', name, f.unique_for_year))
            if (f.unique_for_month and (f.unique_for_month not in exclude)):
                date_checks.append((model_class, 'month', name, f.unique_for_month))
    return (unique_checks, date_checks)
