के संदर्भ में कोड चल रहा है या नहीं, मेरे पास गतिशील विकल्पों वाला एक मॉडल है, और यदि मैं गारंटी दे सकता हूं कि कोड की स्थिति में कोड चल रहा है तो मैं एक खाली विकल्प सूची वापस करना चाहूंगा 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__
का परीक्षण करने के बारे में सोच रहा था, लेकिन मुझे उम्मीद है कि संभवतः एक और अधिक विश्वसनीय तरीका या एपीआई है?
आपकी पसंद कितनी गतिशील हैं? क्या आप कुछ कोड पोस्ट कर सकते हैं? – aumo
निश्चित बात, कोड जोड़ा गया – DanH
आप 'प्रदर्शन' और 'स्थान' कैसे आयात करते हैं? – Ivan