# Monkey-patch Mezzanine's user email address check to allow only
# email addresses at @example.com.
from django.forms import ValidationError
from django.utils.translation import ugettext
from mezzanine.accounts.forms import ProfileForm
from copy import deepcopy
original_clean_email = deepcopy(ProfileForm.clean_email)
def clean_email(self):
email = self.cleaned_data.get("email")
if not email.endswith('@example.com'):
raise ValidationError(
ugettext("Please enter a valid example.com email address"))
return original_clean_email(self)
ProfileForm.clean_email = clean_email
このコードは私のmodels.py
の1つの先頭に追加されています。
私は恐ろしい
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
を取得するrunserverとき、私は
import django
django.setup()
を追加した場合しかし、その後、python manage.py runserver
ちょうど私^C
までハングアップします。
この機能を追加するにはどうすればよいですか?
なぜ、 'django.setup()'を追加することが可能だと思いましたか? Djangoをスタンドアロンスクリプトで使用する場合、 'models.py'でこれを使用するべきではありません。 – Alasdair
私はそれを今知っている!私はスタンドアロンのスクリプトでそれを使って必要なモデルをセットアップしましたが、実際のDjangoプロジェクトではうまくいかないことに気づいていませんでした。 – xnx