'Clean Name'

def clean_name(self):

    data = self.cleaned_data['name']
    query = Q(name=data)
    if (self.instance and self.instance.id):
        query = (query & (~ Q(id=self.instance.id)))
    existing = User.objects.filter(query)
    if existing:
        raise forms.ValidationError((_('User    with    username    %s    already    exists.') % data))
    if (self.instance and (not self.instance.id)):
        user_limit = getattr(settings, 'HARDTREE_SUBSCRIPTION_USER_LIMIT', 0)
        if (user_limit > 0):
            user_number = User.objects.filter(disabled=False).count()
            if (user_number >= user_limit):
                raise forms.ValidationError((_("Sorry,    but    your    subscription    does    not    allow    more    than    %d    users.    You're    currently    at    your    limit.") % user_limit))
    return data
