def create_token(self): """Create a time-stamped token""" token = unicode( hashlib.sha512(str(time.time()) + self.username).hexdigest()) DataToken.delete_by_username(self.username, self.action) # create new one token_instance = DataToken(token=token, username=self.username, action=self.action, date=datetime.now() + self.expiration_delay) return token_instance