Django Terminal Print SQL statement
LOGGING = { 'version': 1, 'disable_existing_loggers': False,'handlers': { 'Console':{ ' Level':'DEBUG', 'class':'logging. Streamhandler', }, }, 'Loggers': { 'Django.db.backends': { 'handlers': ['Console'], 'Propagate': True,' Level':'DEBUG', }, }}
Invoking the Django environment in a python script
ImportOSif __name__=='__main__': Os.environ.setdefault ("Django_settings_module","bms.settings") ImportDjango Django.setup () fromApp01ImportModels Books=models. Book.objects.all ()Print(books)
LOGGING = { 'version': 1, 'disable_existing_loggers': False,'handlers': { 'Console':{ ' Level':'DEBUG', 'class':'logging. Streamhandler', }, }, 'Loggers': { 'Django.db.backends': { 'handlers': ['Console'], 'Propagate': True,' Level':'DEBUG', }, }}
Invoking the Django environment in a python script
ImportOSif __name__=='__main__': Os.environ.setdefault ("Django_settings_module","bms.settings") ImportDjango Django.setup () fromApp01ImportModels Books=models. Book.objects.all ()Print(books)
Customize table names in Django
class Record (models. Model): Pass class Meta: db_table="Record"
customizing char types in Djanggo
# Custom char Types class Fixcharfield (models. Field): def__init__(self, max_length, *args, * *Kwargs) := max_ Length super (). __init__ (Max_length=self.max_length,*args, * *Kwargs ) def db_type (self, Connection): return ' char (%s) '% self.max_length
The Django terminal prints the SQL statement and calls the test script