code: def generate_username(self, user_class):
          
          m = getattr(user_class, 'generate_username', None)
          if m:
              return m()
          else:
              max_length = user_class._meta.get_field(
                  self.username_field).max_length
              return uuid.uuid4().hex[:max_length]
docs: Generate a new username for a user