Last active
February 17, 2020 11:00
-
-
Save mmichealjroberts/15bd70c860d2b5a62a1a6227a67b0ab6 to your computer and use it in GitHub Desktop.
Django 3.0 DB Info Management Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
from django.core.management.base import BaseCommand | |
from django.conf import settings | |
class Command(BaseCommand): | |
help = 'Displays The Currently Connected DB Settings' | |
def handle(self, *args, **kwargs): | |
print("The connection vendor is {}".format(connection.vendor)) | |
print( | |
"The current database engine is {ENGINE}".format(**connection.settings_dict) | |
) | |
print( | |
"Currently connected to host {HOST} on port {PORT}".format(**connection.settings_dict) | |
) | |
if connection.settings_dict['OPTIONS']['sslmode'] == 'require': | |
print( | |
"The database is using encrypted transport methods: SSL is on!" | |
) | |
if connection.settings_dict['ATOMIC_REQUESTS']: | |
print( | |
"The database is using a per view transation based approach - atomic requests are on." | |
) | |
else: | |
print( | |
"The database is not using a per view transation based approach - atomic requests are off." | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment