1
私は作成時にユーザーに電子メールを送信するモデル予約を持っています。電子メールの送信を動的にオフにする方法はありますか?
テスト目的のために、私は時々、数百のReservations
をデータベースに取り込みたいと思います。
これは数千の電子メールを生成する可能性がありますので、電子メールの送信を無効にするか、または可能であれば電子メールのバックエンドを動的に変更したいと考えています。
Reservation
モデルごとにsave
メソッドを実行する必要があるため、一括作成できません。
一時的にsettings.py
を変更するだけですが、設定を変更するのを忘れている可能性があります。
def create_random_reservations(count=10, user='futilestudio'):
users = User.objects.all()
airports = Location.objects.filter(is_airport=True)
cities = Location.objects.filter(is_airport=False)
for n in range(count/2):
dt = datetime(year=2017, month=9, day=random.choice(range(15, 20)), hour=random.choice(range(12, 22)),
minute=random.choice(range(60)))
r = Reservation.objects.create(customer_first_name=get_random_string(10),
customer_last_name=get_random_string(10), flight_number=get_random_string(5),
destination_from=random.choice(airports), destination_to=random.choice(cities),
date_arrival=dt.date(), time_arrival=dt.time(), customer=random.choice(users))
r.confirm(save=True)
パラメータを追加しないでください。send_mail = Trueを確認してください。 – Igor