if len(keys) > 0:
id = int(keys[-1]) + 1
students[str(id)] = self #you actually save the data here
else:
id = 1
# where is the save operation if the db is empty?
You should conditionally determine the id value, then UNconditionally assign it to self.id and save the entire instance to shelve.