Last active
December 8, 2025 14:34
-
-
Save kevinhooke/1c84fc78e226c7d25d294e054e42d6d5 to your computer and use it in GitHub Desktop.
Django notes
This file contains hidden or 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
| # Running dev server: | |
| python3 manage.py runserver | |
| # Adding a user to admin: | |
| python3 manage.py createsuperuser | |
| # Adding app to installed apps: | |
| # In yoursite/settings.py, add to: | |
| INSTALLED_APPS = [ | |
| ] | |
| # Registering a model to be accessible from admin: | |
| # In appname/admin.py: | |
| from .models import Question | |
| admin.site.register(Question) | |
| # Create db migrations: | |
| python3 manage.py makemigrations dashboard | |
| # Perform db migration: | |
| python manage.py migrate | |
| Specific suggestions / recommendations: | |
| # Checking for items in a QuerySet | |
| # Instead of: | |
| if len(somemodel.somerelatedmodel_set.all()) > 0 | |
| # use | |
| if somemodel.somerelatedmodel_set.exists() | |
| # Note the use of '_set' to refer to the set of items for a related property | |
| # Prefer use of f-strings | |
| # Instead of concats: | |
| logger.info("User id: " + userid) | |
| # Use: | |
| logger.info(f"User id: {userid}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment