Skip to content

Instantly share code, notes, and snippets.

@mmichealjroberts
Last active February 17, 2020 11:00
Show Gist options
  • Save mmichealjroberts/15bd70c860d2b5a62a1a6227a67b0ab6 to your computer and use it in GitHub Desktop.
Save mmichealjroberts/15bd70c860d2b5a62a1a6227a67b0ab6 to your computer and use it in GitHub Desktop.
Django 3.0 DB Info Management Command
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