How to do it...

To use the system-check framework, go through these steps:

  1. Create the checks.py file with the following content:
# myproject/apps/viral_videos/checks.py
from
textwrap import dedent

from django.core.checks import Warning, register, Tags


@register(Tags.compatibility)
def settings_check(app_configs, **kwargs):
from django.conf import settings

errors = []

if not settings.ADMINS:
errors.append(
Warning(
dedent("""
The system admins are not set in the project
settings
"""),
obj=settings,
hint=dedent("""
In order to receive notifications when new
videos are
created, define system admins
in your settings, like:

ADMINS = (
("Admin", "administrator@example.com"),
)
"""),
id="viral_videos.W001",
)
)

return errors
  1. Import the checks in the ready() method of the app configuration as follows:
# myproject/apps/viral_videos/apps.py
from
django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class ViralVideosAppConfig(AppConfig):
name = "myproject.apps.viral_videos"
verbose_name = _("Viral Videos")

def ready(self):
from .signals import inform_administrators
from .checks import settings_check
  1. To try the check that you just created, remove or comment out the ADMINS setting and then run the check management command in your virtual environment:

(env)$ python manage.py check
System check identified some issues:

WARNINGS:
<Settings "myproject.settings.dev">: (viral_videos.W001)
The system admins are not set in the project settings

HINT:
In order to receive notifications when new videos are
created, define system admins in your settings, like:

ADMINS = (
("Admin", "administrator@example.com"),
)


System check identified 1 issue (0 silenced).