djangoにおいてカスタムユーザーモデルを使用し、ユーザー登録機能を実装しました。
ログインにはユーザーネームではなく、メールアドレスを使用するように設定しています。
python
1class User(AbstractBaseUser, PermissionsMixin): 2 email = models.EmailField(_('email address'), unique=True) 3 username = models.CharField(_('username'),max_length=20,unique=True) 4 first_name = models.CharField(_('first name'), max_length=20, blank=True) 5 last_name = models.CharField(_('last name'), max_length=20, blank=True)
上記のようなモデルを定義し、user.is_active = Falseにする事で会員削除機能を実装しようと試みました。
python
1User = get_user_model() 2 3class UserDeleteView(LoginRequiredMixin, generic.View): 4 5 def get(self, *args, **kwargs): 6 user = User.objects.get(email=self.request.user.email) 7 user.is_active = False 8 user.save() 9 auth_logout(self.request) 10 return render(self.request,'account/user_delete.html')
しかし、この方法では、user.is_active = Falseによりログインこそ出来なくなるものの、
1、大元のデータベースからは削除されない。
2、再度同じメールアドレスで登録出来ない
等の問題が生じてしまいます。
これらを解消する良い方法あれば教えて頂きたいのです。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/08/28 05:53
2019/08/28 06:36
退会済みユーザー
2019/08/28 09:15