Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
BallsDex Discord Bot
https://github.com/ballsdex-team/ballsdex-discordbot
Admin
Customizable Discord bot to collect and trade countryballs.
Tokens:
19,215
Snippets:
320
Trust Score:
8.1
License:
MIT
Update:
4 months ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Install and configure the bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Commands to build the Docker containers, create an admin user, and start the proxy service. ```bash docker compose build ``` ```bash docker compose run --rm admin-panel python3 -m django createsuperuser ``` ```bash docker compose up -d proxy ``` -------------------------------- ### Install dependencies and initialize bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Commands to set up the environment, verify the installation, and initialize the database and admin panel. ```bash poetry install ``` ```bash poetry shell ``` ```bash python3 -m ballsdex --version ``` ```bash python3 -m ballsdex --reset-settings ``` ```bash cd admin_panel ``` ```bash python3 manage.py migrate ``` ```bash python3 manage.py collectstatic --no-input ``` ```bash cd .. ``` -------------------------------- ### Start the Admin Panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/getting-started.md Commands to initialize or start the admin panel service. ```bash docker compose up -d proxy ``` ```bash DJANGO_SETTINGS_MODULE=admin_panel.settings python3 -m django migrate && uvicorn admin_panel.asgi:application ``` -------------------------------- ### Install project dependencies Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Commands to install uv and synchronize the development environment. ```bash pip install uv uv sync --extra dev ``` -------------------------------- ### Start PostgreSQL with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Command to initialize the database container. ```bash docker compose up -d postgres-db ``` -------------------------------- ### Start the admin panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Commands to migrate, collect static files, and start the ASGI server for the admin panel. ```bash cd admin_panel export DJANGO_SETTINGS_MODULE=admin_panel.settings.dev uv run python manage.py migrate uv run python manage.py collectstatic --no-input uv run uvicorn --reload --reload-include "*.html" admin_panel.asgi:application ``` -------------------------------- ### Define extension setup Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Implement the async setup function required by discord.py to load the Cog into the bot. ```python from typing import TYPE_CHECKING from .cog import YourCog if TYPE_CHECKING: from ballsdex.core.bot import BallsDexBot async def setup(bot: "BallsDexBot"): await bot.add_cog(YourCog(bot)) ``` -------------------------------- ### Install Docker and Git on Linux Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Commands to update the system, install dependencies, and set up the Docker repository. ```bash sudo apt update sudo apt install -y git apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt update apt-cache policy docker-ce sudo apt install -y docker-ce ``` -------------------------------- ### Test Docker Installation Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Runs a hello-world container to verify that Docker is functioning correctly. ```bash docker run hello-world ``` -------------------------------- ### Initialize and Start the Bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Commands to navigate to the directory, activate the virtual environment, and set the database URL. ```bash cd BallsDex-DiscordBot ``` ```bash poetry shell ``` ```bash export BALLSDEXBOT_DB_URL=postgres://username:password@localhost:5432/database_name ``` -------------------------------- ### Run the bot and view help Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Commands to start the bot or display available runtime options. ```bash python3 -m ballsdex ``` ```bash python3 -m ballsdex -h ``` -------------------------------- ### Install WSL on Windows Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Command to install the Windows Subsystem for Linux. ```ps wsl --install ``` -------------------------------- ### Install system dependencies Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Installs Nginx, pwgen, and acl packages on Debian or Ubuntu systems. ```bash sudo apt update sudo apt install nginx pwgen acl ``` -------------------------------- ### Run the full stack with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Build and start all services using Docker Compose. ```bash docker compose build docker compose up -d ``` -------------------------------- ### Initialize database with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Starts the PostgreSQL container in detached mode. ```bash docker compose up -d postgres-db --wait ``` -------------------------------- ### Start the admin panel with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Using-the-new-admin-panel Use this command to start the admin panel service when running the project via Docker. ```bash docker compose up -d admin-panel ``` -------------------------------- ### Verify bot installation Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Check that the bot is correctly installed by printing the version number. ```bash python3 -m ballsdex --version ``` -------------------------------- ### Start the bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Execute the bot process using the Django module. ```bash python3 -m django startbot ``` -------------------------------- ### Navigate to admin panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Enter the admin_panel directory to perform database migrations and start the server. ```bash cd admin_panel ``` -------------------------------- ### Start the bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Run the bot in development and debug mode. ```bash uv run python -m ballsdex --dev --debug ``` -------------------------------- ### Install package via config/extra.toml Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Users add this configuration to their extra.toml to install the package. ```toml [[ballsdex.packages]] location = "git+https://github.com/laggron42/my_cool_repo.git==1.0.0" path = "my_cool_app" enabled = true ``` -------------------------------- ### Launch Bot and Admin Panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Commands to start the bot process and the associated admin panel. ```bash python3 -m ballsdex ``` ```bash cd admin_panel && uvicorn admin_panel.asgi:application ``` -------------------------------- ### Install dependencies Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Use uv to sync dependencies and ensure the correct Python version is available. ```bash uv sync ``` -------------------------------- ### Migration Output Example Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Expected console output after running the makemigrations command. ```ansi Migrations for 'test_app': /code/extra/test_app/test_app/migrations/0001_initial.py + Create model LFBall + Create model Profile ``` -------------------------------- ### Install Poetry Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Install the Poetry package manager using the Python 3.13 module. ```bash python3.13 -m pip install -U poetry ``` -------------------------------- ### Build and start the bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/migrating-windows-wsl.md Command to build the Docker image after migrating to the WSL environment. ```bash docker compose build ``` -------------------------------- ### Start the admin panel without Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Using-the-new-admin-panel Execute these commands in the project root to migrate the database, collect static files, and launch the ASGI application. ```bash cd admin_panel && poetry run python3 manage.py migrate && poetry run python3 manage.py collectstatic --no-input && poetry run uvicorn admin_panel.asgi:application ``` -------------------------------- ### Install pwgen Utility Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Commands to update package lists and install the pwgen utility on Debian or Ubuntu systems. ```bash sudo apt update sudo apt install pwgen ``` -------------------------------- ### Start bot with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Commands to restart containers with the override configuration and enable live-reloading. ```sh docker compose down # clear up old containers and load the new file docker compose up --watch ``` -------------------------------- ### Run the admin panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Command to start the Uvicorn server for the admin panel interface. ```bash cd admin_panel && uvicorn admin_panel.asgi:application ``` -------------------------------- ### Manage Bot Lifecycle Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Commands to start, stop, and monitor the bot containers. ```bash docker compose up ``` ```bash docker compose up -d ``` ```bash docker compose logs -f ``` ```bash docker compose logs -f bot ``` ```bash docker compose logs -f admin-panel ``` ```bash docker compose down ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Configures the repository to run linting and formatting checks automatically before each commit. ```sh pre-commit install ``` -------------------------------- ### Build and manage Docker containers in WSL Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Migrating-from-Windows-to-WSL Essential commands for building, starting, stopping, and monitoring the bot containers. ```bash docker compose build ``` ```bash docker compose up -d ``` ```bash docker compose down ``` ```bash docker compose ps ``` ```bash docker compose logs ``` ```bash docker compose logs bot ``` ```bash docker compose logs admin-panel ``` ```bash docker compose logs bot -f ``` ```bash docker compose restart bot ``` -------------------------------- ### Run the bot with Docker Compose Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Starts the bot and admin panel containers. Use Ctrl+C to stop the process. ```bash docker compose up ``` -------------------------------- ### Run bot and admin panel without Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Commands to set the development settings module and start the bot and admin panel processes manually. ```sh export DJANGO_SETTINGS_MODULE=admin_panel.settings.dev # run the bot like this python3 -m ballsdex --dev --debug # and the admin panel like this uvicorn --reload admin_panel.asgi:application ``` -------------------------------- ### Configure environment for admin panel Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Set the database URL and Django settings module in the shell environment before starting the admin panel. ```bash source .venv/bin/activate export BALLSDEXBOT_DB_URL=postgres://username:password@localhost:5432/database_name export DJANGO_SETTINGS_MODULE="admin_panel.settings.dev" ``` ```ps1 . .\.venv\Scripts\activate.ps1 $Env.BALLSDEXBOT_DB_URL = 'postgres://username:password@localhost:5432/database_name' $Env.DJANGO_SETTINGS_MODULE = 'admin_panel.settings.dev' ``` -------------------------------- ### Verify pip access Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Ensure that pip is available for the installed Python 3.13 environment. ```bash python3.13 -m pip -V ``` -------------------------------- ### Define YAML ID Lists Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Examples of how to format single and multiple ID entries within the YAML configuration file. ```yaml guild-ids: - 1049118743101452329 ``` ```yaml root-role-ids: - 1049119446372986921 - 1049119786988212296 ``` -------------------------------- ### Verify Python version Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Check if the required Python 3.13 version is installed on your system. ```bash python3.13 -V ``` -------------------------------- ### Check Docker Compose version Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Verify the installed version of Docker Compose to ensure it meets the minimum requirement of 2.39.4. ```bash docker compose version ``` -------------------------------- ### Define Custom Django Models Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Example models for a user profile and a looking-for-ball system, utilizing OneToOneField and ForeignKey relationships. ```python from django.db import models from bd_models.models import Ball, Player, Special class Profile(models.Model): # link the profile to exactly one player # if the player is deleted, the profile will be deleted too player = models.OneToOneField(Player, on_delete=models.CASCADE) title = models.CharField(max_length=32) bio = models.TextField() # uncapped in length # this field will be optional, if the other player is deleted, then the favorite is set back to null # it's a ForeignKey (OneToMany) instead of a OneToOneField, since a player may be the favorite friend of multiples favorite_friend = models.ForeignKey(Player, on_delete=models.SET_NULL, null=True) class Meta: constraints = [ # a simple restriction to ensure the player doesn't set themselves as favorite friend models.CheckConstraint(condition=~models.Q(player=models.F("favorite_friend")), name="friend_neq_player") ] class LFBall(models.Model): # this time we will be using a ForeignKey as one player may have multiple LFBall entries player = models.ForeignKey(Player, on_delete=models.CASCADE) # same for the ball the player is looking for ball = models.ForeignKey(Ball, on_delete=models.CASCADE) # we will also add an optional "special" specifier # if a special gets deleted, the LF entry should also be removed special = models.ForeignKey(Special, on_delete=models.CASCADE, null=True) ``` -------------------------------- ### Initialize database Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Run Django migrations to set up the database schema. ```bash python3 -m django migrate ``` -------------------------------- ### Download and navigate to source code Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Commands to clone the repository and enter the project directory. ```bash git clone https://github.com/laggron42/BallsDex-DiscordBot.git ``` ```bash cd BallsDex-DiscordBot ``` -------------------------------- ### Configure production settings via shell Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Commands to navigate to the settings directory and initialize the production configuration file. ```bash cd admin_panel/admin_panel/settings cp production.example.py production.py pwgen -n 64 1 nano production.py ``` -------------------------------- ### Initialize Production Settings Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Commands to prepare the production configuration file for the Django application. ```bash cd config ``` ```bash cp production.example.py production.py ``` ```bash pwgen -n 64 1 ``` ```bash nano production.py ``` -------------------------------- ### Initialize repository directory Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Create a new directory within the extra folder to serve as the package repository. ```sh mkdir extra/my_cool_repo ``` -------------------------------- ### Initialize a git repository Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Commands to initialize a new git repository for the package. ```bash cd extra/my_cool_repo git init ``` -------------------------------- ### Import database dump into WSL Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Migrating-from-Windows-to-WSL Commands to initialize the database container and import the SQL dump file. ```bash docker compose up -d postgres-db ``` ```bash cat data-dump.sql | docker compose exec -T psql -U ballsdex ballsdex ``` -------------------------------- ### Configure environment variables Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Set up the database URL and Django settings module for the bot environment. ```bash # open the bot's directory cd BallsDex-DiscordBot # activate the virtual environment source .venv/bin/activate # open the django directory cd admin_panel # export the database env var export BALLSDEXBOT_DB_URL=postgres://username:password@localhost:5432/database_name export DJANGO_SETTINGS_MODULE="admin_panel.settings.dev" ``` ```ps1 # open the bot's directory cd BallsDex-DiscordBot # activate the virtual environment . .\.venv\Scripts\activate.ps1 # export the database env var $Env.BALLSDEXBOT_DB_URL = 'postgres://username:password@localhost:5432/database_name' $Env.DJANGO_SETTINGS_MODULE = 'admin_panel.settings.dev' ``` -------------------------------- ### Create Superuser via Command Line Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Commands to initialize a superuser account, depending on whether the application is running inside Docker. ```bash docker compose exec admin-panel python3 -m django createsuperuser ``` ```bash DJANGO_SETTINGS_MODULE=admin_panel.settings python3 -m django createsuperuser ``` -------------------------------- ### Import Legacy Settings Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Commands to migrate existing config.yml settings into the new admin panel database. ```bash cat config.yml | docker compose exec -iT admin-panel python3 -m django import_settings_yml ``` ```bash DJANGO_SETTINGS_MODULE=admin_panel.settings python3 -m django import_settings_yml config.yml ``` -------------------------------- ### View bot run options Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Display help information for available bot runtime arguments. ```bash python3 -m django startbot -h ``` -------------------------------- ### Create Override Configuration File Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/hosting-multiple-bots.md Initializes the override file required to customize port settings without modifying the base configuration. ```bash touch docker-compose.override.yml ``` -------------------------------- ### Perform a database backup Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Create a pre-migration SQL dump of the database to ensure data safety before the upgrade. ```bash docker compose up -d postgres-db --wait && \ docker compose exec postgres-db pg_dump -U ballsdex ballsdex -f data-dump.sql && \ docker compose cp postgres-db:data-dump.sql pre-migration-data-dump.sql ``` ```bash pg_dump -U ballsdex ballsdex -f pre-migration-data-dump.sql ``` -------------------------------- ### Create Django application Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Initialize a new Django application within the custom repository folder. ```sh docker compose run --rm migration python3 -m django startapp my_cool_app /code/extra/my_cool_repo/my_cool_app ``` ```sh export DJANGO_SETTINGS_MODULE="admin_panel.settings.dev" cd extra/my_cool_repo python3 -m django startapp my_cool_app ``` -------------------------------- ### Configure the bot using YAML Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Use this configuration file to define the bot token, command prefixes, administrative roles, and package settings. ```yaml # yaml-language-server: $schema=json-config-ref.json # paste the bot token after regenerating it here discord-token: INSERT_TOKEN_HERE # prefix for old-style text commands, mostly unused text-prefix: b. # define the elements given with the /about command about: # define the beginning of the description of /about # the other parts is automatically generated description: > Collect countryballs on Discord, exchange them and battle with friends! # override this if you have a fork github-link: https://github.com/laggron42/BallsDex-DiscordBot # valid invite for a Discord server discord-invite: https://discord.gg/ballsdex # BallsDex official server terms-of-service: https://gist.github.com/laggron42/52ae099c55c6ee1320a260b0a3ecac4e privacy-policy: https://gist.github.com/laggron42/1eaa122013120cdfcc6d27f9485fe0bf # override the name "countryballs" in the bot collectible-name: countryball # override the name "BallsDex" in the bot bot-name: BallsDex # players group cog command name # this is /balls by default, but you can change it for /animals or /rocks for example players-group-cog-name: balls # enables the /admin command admin-command: # all items here are list of IDs. example on how to write IDs in a list: # guild-ids: # - 1049118743101452329 # - 1078701108500897923 # list of guild IDs where /admin should be registered guild-ids: - 1049118743101452329 # list of role IDs having full access to /admin root-role-ids: - 1049119446372986921 - 1049119786988212296 - 1095015474846248970 # list of role IDs having partial access to /admin admin-role-ids: - 1073775485840003102 - 1073776116898218036 packages: - ballsdex.packages.admin - ballsdex.packages.balls - ballsdex.packages.config - ballsdex.packages.countryballs - ballsdex.packages.info - ballsdex.packages.players - ballsdex.packages.trade # prometheus metrics collection, leave disabled if you don't know what this is prometheus: enabled: true host: "0.0.0.0" port: 15260 # manage bot ownership owners: # if enabled and the application is under a team, all team members will be considered as owners team-members-are-owners: true # a list of IDs that must be considered owners in addition to the application/team owner co-owners: ``` -------------------------------- ### Create a superuser account Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Using-the-new-admin-panel Commands to create an administrative account for the panel. Use the Docker-specific command if running inside a container. ```bash docker compose exec admin-panel python3 manage.py createsuperuser ``` ```bash cd admin_panel && poetry run python3 manage.py createsuperuser ``` -------------------------------- ### Build and migrate with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Rebuilds the bot container and executes database migrations. ```bash docker compose build ``` ```bash docker compose up migration ``` -------------------------------- ### Verify package loading in logs Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Check the bot logs to confirm that the custom extension has been successfully loaded. ```text 2025-12-16 14:32:17 INFO ballsdex.core.bot Packages loaded: admin, balls, guildconfig, countryballs, info, players, trade, my_cool_ext ``` -------------------------------- ### Configure Nginx access and site file Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Commands to grant Nginx file access and create the site configuration file. ```bash sudo setfacl -m g:www-data:rx $HOME ``` ```bash pwd ``` ```bash sudo nano /etc/nginx/sites-available/example.com ``` -------------------------------- ### Create a database dump Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Backing-up-and-restoring-data Generate a SQL dump file containing all database data. ```bash docker compose up -d postgres-db && docker compose exec pg_dump -U ballsdex ballsdex > data-dump.sql ``` ```bash pg_dump -U ballsdex ballsdex > data-dump.sql ``` -------------------------------- ### Import database dump with Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Pipes a SQL dump file into the PostgreSQL container. ```bash cat final-data-dump.sql | docker compose exec -T postgres-db psql -U ballsdex ballsdex ``` -------------------------------- ### Activate virtual environment Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex-no-docker.md Activate the project's virtual environment based on the operating system. ```bash source .venv/bin/activate ``` ```ps1 . .\.venv\Scripts\activate.ps1 ``` -------------------------------- ### Navigate to the bot directory Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Changes the current working directory to the downloaded bot folder. ```bash cd BallsDex-DiscordBot ``` -------------------------------- ### Prepare data for migration Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Drop specific Django authentication tables and create a final backup for the migration process. ```bash docker compose up -d postgres-db --wait && \ docker compose run --rm migration python3 manage.py migrate admin zero && \ docker compose run --rm migration python3 manage.py migrate auth zero && \ docker compose run --rm migration python3 manage.py migrate contenttypes zero && \ docker compose run --rm migration python3 manage.py migrate sessions zero && \ docker compose exec postgres-db pg_dump -U ballsdex ballsdex -f data-dump.sql && \ docker compose cp postgres-db:data-dump.sql final-data-dump.sql ``` ```bash # activate your venv and export BALLSDEXBOT_DB_URL cd admin_panel python3 manage.py migrate admin zero python3 manage.py migrate auth zero python3 manage.py migrate contenttypes zero python3 manage.py migrate sessions zero pg_dump -U ballsdex ballsdex -f final-data-dump.sql ``` -------------------------------- ### Configure database environment variable Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Export the database connection string before running the application. ```bash export BALLSDEXBOT_DB_URL="postgres://ballsdex:defaultballsdexpassword@localhost:5432/ballsdex" ``` -------------------------------- ### Export database URL environment variable Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Set the database connection string for the bot session. ```bash export BALLSDEXBOT_DB_URL=postgres://username:password@localhost:5432/database_name ``` ```powershell $Env.BALLSDEXBOT_DB_URL = 'postgres://username:password@localhost:5432/database_name' ``` -------------------------------- ### Import a database dump Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Backing-up-and-restoring-data Import a previously generated SQL dump into the database. The database must be completely empty before importing. ```bash docker compose up -d postgres-db && cat data-dump.sql | docker compose exec -T postgres-db psql -U ballsdex ballsdex ``` ```bash psql -U ballsdex ballsdex -f data-dump.sql ``` -------------------------------- ### Switch to v3 branch Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Commands to update the local repository to the v3 branch. ```bash git switch v3 git pull ``` -------------------------------- ### Apply Docker Compose Changes Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Command to recreate containers to apply the new environment configuration. ```bash docker compose up -d ``` -------------------------------- ### Run development tools in Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Execute linting and type checking inside the running bot container. ```bash docker compose exec bot ruff check . docker compose exec bot pyright . ``` -------------------------------- ### Generate Django Migrations Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Commands to generate initial database migrations for the custom application. ```bash docker compose run --rm migration python3 -m django makemigrations my_cool_app ``` ```bash python3 -m django makemigrations my_cool_app ``` -------------------------------- ### Commit and push changes to remote Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Commands to stage, commit, and push the repository to a remote host. ```bash git add --all # review that only the files you want to push are listed git status # and commit git commit -m "First commit" ``` ```bash git remote add origin https://github.com/laggron42/my_cool_repo.git git push -u origin master ``` -------------------------------- ### Clone the repository Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Migrating-to-a-git-install Use this command to download the Ballsdex repository to your local machine. ```bash git clone https://github.com/laggron42/BallsDex-DiscordBot.git ``` -------------------------------- ### Enable and reload Nginx configuration Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Commands to link the configuration file and reload the Nginx service. ```bash sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ ``` ```bash sudo nginx -s reload ``` -------------------------------- ### Configure VS Code for YAML Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Command to open the configuration file in Visual Studio Code for easier editing. ```bash code config.yml ``` -------------------------------- ### Configure pyproject.toml metadata Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Define project metadata, dependencies, and URLs for the package. ```toml [project] name = "my_cool_repo" version = "1.0.0" description = "A very nice repository" license = "MIT" # replace with your own license license-files = ["LICENSE"] authors = [ { name = "laggron42", email = "laggron42@ballsdex.com" }, ] readme = "README.md" dependencies = [ # you can require a specific version of ballsdex here "ballsdex>=3.0.0", # and extra dependencies if needed ] [project.urls] # put your own links here # https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-project-urls Homepage = "https://github.com/username/repo-name" ``` -------------------------------- ### Configure custom package in config/extra.toml Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Define the package location and path in the configuration file. The location field is specific to Docker environments. ```toml [[ballsdex.packages]] location = "/code/extra/my_cool_repo" path = "my_cool_app" enabled = true editable = true ``` ```toml [[ballsdex.packages]] location = "" # this only matters for Docker path = "my_cool_app" enabled = true editable = true ``` -------------------------------- ### Verify PostgreSQL connection Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Use this command to test the connection to your PostgreSQL database instance. ```bash psql -c "\l" postgres://username:password@localhost:5432/database_name ``` -------------------------------- ### Configure pyproject.toml Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Define the package metadata and dependencies in the pyproject.toml file. ```toml [project] name = "my_cool_repo" version = "1.0.0" dependencies = [ # you can require a specific version of ballsdex here "ballsdex>=3.0.0", ] ``` -------------------------------- ### Run pre-commit checks manually Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Executes all configured linting and formatting rules against the codebase manually. ```sh pre-commit run -a ``` -------------------------------- ### Restore a backup on Windows Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/backup-and-transfers.md Restores an extracted SQL file on Windows systems. ```bash docker compose up -d postgres-db && \ cat data-dump.sql | \ docker compose exec -T postgres-db psql -U ballsdex ballsdex ``` ```bash psql -U ballsdex ballsdex -f data-dump.sql ``` -------------------------------- ### Restore a backup on macOS/Linux Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Backing-up-and-restoring-data Restore a compressed backup file on Unix-based systems. ```bash docker compose up -d postgres-db && zcat ballsdex-latest.sql.gz | docker compose exec -T postgres-db psql -U ballsdex ballsdex ``` ```bash zcat ballsdex-latest.sql.gz | psql -U ballsdex ballsdex ``` -------------------------------- ### Configure UFW Firewall Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Commands to secure the server by restricting incoming connections and allowing necessary traffic. ```bash sudo ufw default deny incoming ``` ```bash sudo ufw default allow outgoing ``` ```bash sudo ufw allow OpenSSH ``` ```bash sudo ufw allow 'Nginx Full' ``` ```bash sudo ufw enable ``` -------------------------------- ### Open directory in system explorer Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Commands to open the current directory in the system's graphical file explorer. ```bash explorer.exe . ``` ```bash open . ``` ```bash xdg-open . ``` -------------------------------- ### Run migrations without Docker Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Executes Django migrations manually. ```bash cd admin_panel && python3 -m django migrate ``` -------------------------------- ### Configure Authentication Backends Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Modify the AUTHENTICATION_BACKENDS setting in production.py to enable or disable Discord OAuth2 and password-based authentication. ```py AUTHENTICATION_BACKENDS = [ # "social_core.backends.discord.DiscordOAuth2", "django.contrib.auth.backends.ModelBackend", ] ``` ```py AUTHENTICATION_BACKENDS = [ "social_core.backends.discord.DiscordOAuth2", # "django.contrib.auth.backends.ModelBackend", ] ``` -------------------------------- ### View bot logs Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Commands to monitor live logs for the bot or admin panel containers. ```bash docker compose logs -f ``` ```bash docker compose logs -f bot ``` ```bash docker compose logs -f admin-panel ``` -------------------------------- ### Update and Restart Bot Commands Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Commands to pull updates, reset local changes if necessary, and rebuild the Docker environment. ```bash git pull ``` ```bash git reset --hard HEAD ``` ```bash docker compose down ``` ```bash docker compose build ``` ```bash docker compose up ``` ```bash docker compose up -d ``` -------------------------------- ### Define docker-compose.override.yml Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/CONTRIBUTING.md Configuration for local development overrides in Docker. ```yaml services: bot: command: python3 -m ballsdex --dev --debug environment: - "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev" build: args: - "INSTALL_DEV_DEPS=1" admin-panel: environment: - "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev" build: args: - "INSTALL_DEV_DEPS=1" migration: build: args: - "INSTALL_DEV_DEPS=1" ``` -------------------------------- ### Docker CLI commands for Linux Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/migrating-windows-wsl.md Commonly used Docker Compose commands for managing the bot in a Linux/WSL environment. ```bash docker compose up -d ``` ```bash docker compose down ``` ```bash docker compose ps ``` ```bash docker compose logs ``` ```bash docker compose logs bot ``` ```bash docker compose logs admin-panel ``` ```bash docker compose logs bot -f ``` ```bash docker compose restart bot ``` -------------------------------- ### Configure Docker development overrides Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Create this file to enable developer options and debug mode when running the bot via Docker. ```yml services: bot: command: python3 -m ballsdex --dev --debug environment: - "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev" admin-panel: environment: - "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev" ``` -------------------------------- ### Clone the Ballsdex Repository Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/hosting-multiple-bots.md Downloads the bot source code into a unique directory specified by the user. ```bash git clone https://github.com/laggron42/BallsDex-DiscordBot.git <botname> ``` -------------------------------- ### Configure Docker Compose Override Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md YAML configuration to apply production settings to containers without modifying the base compose file. ```yaml services: bot: environment: - "DJANGO_SETTINGS_MODULE=config.production" admin-panel: environment: - "DJANGO_SETTINGS_MODULE=config.production" ``` -------------------------------- ### Configure Custom Port Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/hosting-multiple-bots.md Defines the port mapping in the override file to prevent conflicts with other running bot instances. ```yaml services: proxy: ports: !override - "127.0.0.1:8001:80" ``` -------------------------------- ### Define a minimal .gitignore Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Exclude common Python build and cache files from version control. ```gitignore # Python stuff *.pyc __pycache__ *.egg-info ``` -------------------------------- ### Reset Admin Password Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Use this command if you have forgotten your admin panel credentials. ```bash docker compose run --rm admin-panel python3 -m django changepassword <username> ``` -------------------------------- ### Verify Docker Status Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Expected output format when checking the status of the Docker service. ```text ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-01 21:30:25 UTC; 22s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 7854 (dockerd) Tasks: 7 Memory: 38.3M CPU: 340ms CGroup: /system.slice/docker.service └─7854 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ``` -------------------------------- ### Wipe the database Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Backing-up-and-restoring-data Reset the PostgreSQL database to prepare for a fresh import or restoration. ```bash docker compose down --volumes ``` ```bash psql -U ballsdex ballsdex -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" ``` -------------------------------- ### Configure Docker User Permissions Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/installation/installing-ballsdex.md Adds the current user to the docker group to avoid using sudo for Docker commands. ```bash sudo usermod -aG docker ${USER} su - ${USER} ``` -------------------------------- ### Update the Bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex-without-Docker Sequence of commands to pull the latest code, update dependencies, and migrate the admin panel database. ```bash git pull ``` ```bash poetry install ``` ```bash cd admin_panel ``` ```bash python3 manage.py migrate ``` ```bash python3 manage.py collectstatic --no-input ``` -------------------------------- ### Register Django models in admin.py Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Basic configuration to register models in the Django admin panel. ```python from django.contrib import admin from .models import LFBall, Profile @admin.register(Profile) class ProfileAdmin(admin.ModelAdmin): pass @admin.register(LFBall) class LFBallAdmin(admin.ModelAdmin): pass ``` -------------------------------- ### Define a custom Cog Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Create a class inheriting from commands.Cog to define bot commands and listeners. ```python from typing import TYPE_CHECKING from discord import app_commands from discord.ext import commands if TYPE_CHECKING: from ballsdex.core.bot import BallsDexBot class YourCog(commands.Cog): def __init__(self, bot: "BallsDexBot"): self.bot = bot @commands.command() async def hello(self, ctx: commands.Context["BallsDexBot"]): await ctx.send("Hello World!") ``` -------------------------------- ### Set Django Environment Variable Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Command to set the environment variable for production settings when not using Docker. ```bash export DJANGO_SETTINGS_MODULE=config.production ``` -------------------------------- ### Optimize admin model loading with autocomplete_fields Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Use autocomplete_fields to prevent loading all items for large models in the admin panel. ```python @admin.register(Profile) class ProfileAdmin(admin.ModelAdmin): autocomplete_fields = ("player", "favorite_friend") @admin.register(LFBall) class LFBallAdmin(admin.ModelAdmin): autocomplete_fields = ("player", "ball") ``` -------------------------------- ### Wipe the database Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/misc/upgrading-to-3.0.md Remove existing database volumes to prepare for the Postgres 18 upgrade. ```bash docker compose down --volumes ``` -------------------------------- ### Register extension in AppConfig Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Add the dpy_package attribute to your Django AppConfig to enable the extension. ```python from django.apps import AppConfig class MyCoolAppConfig(AppConfig): name = "my_cool_app" dpy_package = "my_cool_app.my_cool_ext" ``` -------------------------------- ### Implement Asynchronous Database Queries in Cogs Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/dev/custom-package.md Usage of asynchronous Django ORM methods within a Discord command, ensuring compatibility with the bot's event loop. ```python ... from bd_models.models import Player from ..models import Profile, LFBall class YourCog(commands.Cog): ... @app_commands.command() async def profile(self, interaction: discord.Interaction["BallsDexBot"], user: discord.User | None = None): user = user or interaction.user try: player = await Player.objects.aget(discord_id=user.id) # pre-fetch the favorite friend's details profile = await Profile.objects.aget(player=player).prefetch_related("favorite_friend") except Player.DoesNotExist: await interaction.response.send_message("No such player.", ephemeral=True) return except Profile.DoesNotExist: await interaction.response.send_message("No profile associated.", ephemeral=True) return text = ( f"# {user.name}'s profile\n" f"-# {profile.title}\n" f"{profile.bio}\n" ) if profile.favorite_friend: text += f"Favorite friend: <@{profile.favorite_friend.discord_id}>\n" lf_query = LFBall.objects.filter(player=player) if await lf_query.aexists(): text += f"## Looking for\n" async for ball in lf_query: text += f"- {ball.country}\n" await interaction.response.send_message(text) ``` -------------------------------- ### Stop the bot Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Backing-up-and-restoring-data Ensure the bot is fully turned off before performing backups or transfers. ```bash docker compose down ``` -------------------------------- ### Nginx server block configuration Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Configuration template for the Nginx server block. Ensure the domain and path are updated to match your environment. ```nginx server { listen 80; listen [::]:80; client_max_body_size 100m; server_name example.com; # TODO: change domain location / { proxy_set_header Host $http_host; proxy_pass http://localhost:8000; # if you have a different port number, change here } location ~ ^/(static|media)/ { root /home/user/BallsDex-DiscordBot/admin_panel; # TODO: change the path of your bot's folder } } ``` -------------------------------- ### Show hidden files on macOS Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Migrating-to-a-git-install Configures Finder to display hidden files via the terminal. ```bash defaults write com.apple.Finder AppleShowAllFiles true ``` -------------------------------- ### Update PostgreSQL image version Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Installing-Ballsdex Modify the docker-compose.yml file to specify the PostgreSQL 17 image. ```diff - image: postgres + image: postgres:17 ``` -------------------------------- ### Retrieve Server IP Address Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/docs/selfhosting/admin-panel/exposing-to-internet.md Command to identify the public IP address of the Linux server. ```bash curl http://ipinfo.io/ip ``` -------------------------------- ### Disable Discord OAuth2 in production Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Modify the authentication backends in production.py to disable the Discord login button and rely on local account management. ```py AUTHENTICATION_BACKENDS = [ # "social_core.backends.discord.DiscordOAuth2", "django.contrib.auth.backends.ModelBackend", ] ``` -------------------------------- ### Disable password authentication Source: https://github.com/ballsdex-team/ballsdex-discordbot/wiki/Serving-the-admin-panel-online Configuration for production.py to restrict authentication to Discord OAuth2 only. ```python AUTHENTICATION_BACKENDS = [ "social_core.backends.discord.DiscordOAuth2", # "django.contrib.auth.backends.ModelBackend", ] ``` -------------------------------- ### Custom Ball Model Admin Change Form Template Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/admin_panel/templates/admin/bd_models/ball/change_form.html Extends the standard Django admin change form to provide custom functionality for the Ball model, including conditional rendering of object tools and a ball preview. ```html+django {% extends "admin/change_form.html" %} {% load i18n admin_urls static admin_modify %} {% block content %} {% if request.resolver_match.url_name == "bd_models_ball_change" %} {% block object-tools %} {% if change and not is_popup %} {% block object-tools-items %} {% change_form_object_tools %} {% endblock %} {% endif %} {% endblock %} {% csrf_token %}{% block form_top %}{% endblock %} {% if is_popup %}{% endif %} {% if to_field %}{% endif %} {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} {% if errors %} {% blocktranslate count counter=errors|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %} {{ adminform.form.non_field_errors }} {% endif %} {% block field_sets %} {% for fieldset in adminform %} {% include "admin/includes/fieldset.html" with heading_level=2 prefix="fieldset" id_prefix=0 id_suffix=forloop.counter0 %} {% endfor %} {% endblock %} {% block after_field_sets %}{% endblock %} {% block inline_field_sets %} {% for inline_admin_formset in inline_admin_formsets %} {% include inline_admin_formset.opts.template %} {% endfor %} {% endblock %} {% block after_related_objects %}{% endblock %} {% block submit_buttons_bottom %}{% submit_row %}{% endblock %} {% block admin_change_form_document_ready %} {% endblock %} {# JavaScript for prepopulated fields #} {% prepopulated_fields_js %} {% include "generate_ball_preview.html" %} {% else %} {{ block.super }} {% endif %} {% endblock %} ``` -------------------------------- ### Extend Django Admin Change Form Source: https://github.com/ballsdex-team/ballsdex-discordbot/blob/v3/admin_panel/templates/admin/bd_models/trade/change_form.html Overrides the after_related_objects block to inject custom trade object display logic. ```html {% extends "admin/change_form.html" %} {% block after_related_objects %} {% if original %} Trade objects ------------- {% for items in trade_objects %} {% for item in items %} {% endfor %} {% endfor %} [{{ player1 }}]({% url 'admin:bd_models_player_change' player1.id %}) [{{ player2 }}]({% url 'admin:bd_models_player_change' player2.id %}) {% if item %} [{{ item.ballinstance.description }}]({% url 'admin:bd_models_ballinstance_change' item.ballinstance.id %}) {% else %} - {% endif %} Total items: {{ player1_len }} Total items: {{ player2_len }} {% endif %} {% endblock %} ```