'Validate the name field. Enforce uniqueness constraint on \'name\' field'

def clean_name(self):

    name = (self.cleaned_data.get('name').strip() or None)
    if (not self.instance.pk):
        try:
            CourseEmailTemplate.get_template(name)
            raise ValidationError('Name    of    "{}"    already    exists,    this    must    be    unique.'.format(name))
        except CourseEmailTemplate.DoesNotExist:
            pass
    return name
