2

django adminで、ユーザーにスーパーユーザーステータスが与えられたら、チェックを実行したいと思います。ユーザーの電子メールが*.company.comの形式であるかどうかを確認したい

これを行うための最良の方法は何ですか?

4

1 に答える 1

5

シグナルを作成します:

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メソッドが実行されます

于 2012-08-10T22:10:45.580 に答える