は、私は、ダイナミックな選択肢でモデルを持っているコマンドコードが移行のコンテキストで実行されているかどうかを検出し、私はコードがのイベントで実行されていることを保証できる場合は、空の選択リストを返したいですdjango-admin.py migrate/makemigrations
コマンドを使用して、無意味な選択肢の変更を作成または警告しないようにします。/makemigrationsは、
コード:
from artist.models import Performance
from location.models import Location
def lazy_discover_foreign_id_choices():
choices = []
performances = Performance.objects.all()
choices += {performance.id: str(performance) for performance in performances}.items()
locations = Location.objects.all()
choices += {location.id: str(location) for location in locations}.items()
return choices
lazy_discover_foreign_id_choices = lazy(lazy_discover_foreign_id_choices, list)
class DiscoverEntry(Model):
foreign_id = models.PositiveIntegerField('Foreign Reference', choices=lazy_discover_foreign_id_choices(),)
だから私は、私はlazy_discover_foreign_id_choices
に実行コンテキストを検出することができれば、私は出力に空の選択リストを選択することができると思います。私はsys.argv
と__main__.__name__
をテストしようと考えていましたが、おそらくもっと信頼できる方法やAPIがあると思っていますか?私は考えることができる
どのように正確にあなたの選択肢は動的ですか?いくつかのコードを投稿できますか? – aumo
確かに、コードが追加されました – DanH
'Performance'と' Location'はどうやってインポートされますか? – Ivan