def form_valid(self, form):
        device = self.get_device()
        device.token_set.all().delete()
        for n in range(self.number_of_tokens):
            device.token_set.create(token=StaticToken.random_token())

        return redirect(self.redirect_url)
Delete existing backup codes and generate new ones.
dataset/ETHPy150Open Bouke/django-two-factor-auth/two_factor/views/core.py/BackupTokensView.form_valid