Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
djangoモデルクラスはシングルトン/一度だけ実装されていますか? そのような
from .models import MODEL # some code a = MODEL # in some other file from .models import MODEL # some code b = MODEL # some code a is b # always True?
モデル クラス自体はシングルトンではなく、複数回インスタンス化できますが、Python のインポート メカニズムではインポート パスごとに 1 回だけインスタンス化されます。同じモジュールの後続のインポートは、既存のインポートへの参照をコピーします。
TL;DR: 奇妙なインポート エッジ ケースを除いて、コードは機能するはずです。