Reduce your Django development costs

Money

Django Doctor checks that your code follows the Django documentation maintainability best practices, and offers the fix to reduce developer effort.

This frees your team to be more agile - they can focus on adding value rather than fighting with old tech debt.

Try the Django Doctor maintainability challenge to see the improvements Django Doctor suggests.

Django Doctor protects you against these maintainability anti-patterns:

  • Importing models.py into migrations

    maintainabilityhigh

    It's better to use apps.get_model, which guarantees the Model's fields will reflect the fields in the database even if models.py is vastly out of step with the database.

    Read more
  • Missing reverse migration

    maintainabilityhigh

    It's good to, as a minimum, specify noop in RunPython so the migration can be skipped when going backwards, and even better to specify a function that undoes the migration.

    Read more
  • Hard-coded static asset URL in template

    maintainabilitymedium

    Hard-coding static asset urls is brittle because the place the files are stored depends on the `STATICFILES_STORAGE` used - so if in prod the storage backend uploads to S3 or even renames the file then this hard-coded URL will break.

    Using "{% static ... %}" solves that as it knows exactly where the files are stored.

    Read more
  • Middleware order

    maintainabilityhigh

    The order of middleware affections the outcome.

    Some middleware are dependant on the functionality of other middlware. For example a middleware that requires usage of request.session should come after the SessionMiddleware.

    Read more
  • URL name not unique

    maintainabilityhigh

    URL names must be unique otherwise reverse('url_name') and {% url 'url_name' %} will link to the "wrong" page half of the time.

    Read more
  • Using reverse_lazy where reverse would be better

    maintainabilitylow

    Using reverse(...) is better than using reverse_lazy(...) when the url is being reversed after URLConf has been loaded.

    Read more
  • Middleware should be near the end

    maintainabilityhigh

    Incorrectly ordered middleware can stop the middleware working as intended.

    Read more
  • Middleware should be near the top

    maintainabilityhigh

    Incorrectly ordered middleware can stop the middleware working as intended.

    Read more
  • Hard-coded URL in template

    maintainabilitymedium

    Hard-coding urls makes changing URLs harder, and makes linking to the wrong page easier - so harms maintainability.

    Read more
  • Brittle unique_for

    maintainabilitymedium

    unique_for_date/month/year is very brittle and over time will likely be a source for unexpected behaviour.

    Read more
  • Importing setting file directly

    maintainabilitymedium

    Using from django.conf import settings simplifies the code and makes it more maintainable.

    Read more
  • CharField with huge max_length

    maintainabilitylow

    Using TextField for very long string fields would simplify the code and make is easier to maintain.

    Read more
  • Deprecated NullBooleanField

    maintainabilitymedium

    NullBooleanField is deprecated and will be removed a future version of Django.

    Read more
  • Redundant default arguments

    maintainabilitylow

    Stating defaults add complexity when reading the code but does not change Django's behaviour.

    Read more
  • Redundant setting

    maintainabilitylow

    Stating defaults add complexity when reading the code but does not change Django's behaviour.

    Read more
  • Field allows null but not blank

    maintainabilitylow

    If null is True and blank is False then validation becomes more complex.

    Read more
  • Non-unique primary_key

    maintainabilityhigh

    A non-unique primary key allows the same value to be used for multiple records thus multiple results could be returned for Model.objects.get(pk=1).

    Read more
  • Relative path in TEMPLATES setting

    maintainabilityhigh

    The TEMPLATE setting is a list of the template engines used when finding template files and rendering them.

    The DIRS key within the TEMPLATE list denotes the directories where the engine should look for template source files.

    DIRS must be absolute paths. Relative paths will not work.

    Read more
  • Back slashes in TEMPLATES settings

    maintainabilityhigh

    The TEMPLATE setting is a list of the template engines used when finding template files and rendering them.

    The DIRS key within the TEMPLATE list denotes the directories where the engine should look for template source files.

    DIRS must be forward slashes, even in Windows. Forward slashes do not need escaping, and they are cross Operating System compatible.

    Read more
  • Nullable string field

    maintainabilitylow

    ORM queries and Python code are made more complex because values will sometimes be None and other times str.

    Read more
  • ForeignKey missing related_name

    maintainabilitylow

    ORM queries are more readable and relationships more explicit when related_name is specified.

    Read more
  • Model method order

    maintainabilitylow

    Increasing standardisation and predictability of your code style helps other developers read your code.

    Read more
  • Admin class not in admin.py

    maintainabilitymedium

    Predictable project structure and following common patterns simplifies maintenance of a codebase.

    Django developers come to expect Admin-related objects to be in admin.py. Failure to do this will result in more time spent looking for where code lives.

    Read more
  • Tall Model

    maintainabilitylow

    A taller Model with many fields may be more difficult to maintain than a shorter Model with fewer fields.

    Read more
  • Huge models.py

    maintainabilitylow

    Taller models.py with many Models may be more difficult to maintain than shorter models.py with fewer Models.

    Read more
  • Tall models.py with a common prefix

    maintainabilitylow

    Taller models.py with many Models may be more difficult to maintain than shorter models.py with fewer Models.

    Read more
  • Are you ready to improve your team agility through lower tech debt? Get Django Doctor.