django adminで、ユーザーにスーパーユーザーステータスが与えられたら、チェックを実行したいと思います。ユーザーの電子メールが*.company.comの形式であるかどうかを確認したい
これを行うための最良の方法は何ですか?
django adminで、ユーザーにスーパーユーザーステータスが与えられたら、チェックを実行したいと思います。ユーザーの電子メールが*.company.comの形式であるかどうかを確認したい
これを行うための最良の方法は何ですか?
シグナルを作成します:
from django.db.models.signals import post_save
from django.contrib.auth.models import User
def check_superuser(sender, instance, signal, *args, **kwargs):
if sender is User and instance.is_superuser and not instance.email.endswith('@company.com'):
...
post_save.connect(check_superuser, sender=User)
User
したがって、のインスタンスが保存されるたびに、上記のcheck_superuser
メソッドが実行されます