Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions django/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
lib/
bin/
include/
# Virtual environment
venv/

# Database
*.sqlite3
db.sqlite3

# Python cache
__pycache__/
*.py[cod]
*$py.class
*.so

# Django
*.log
local_settings.py
23 changes: 16 additions & 7 deletions django/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ From the project root run `script/django/start`

## Database

- **Database console** `./django/manage.py dbshell`
(Run all the below from the Django folder. `minicom-public/django`. Make sure the virtual env is activated: `source venv/bin/activate`)

- **Database console** `./manage.py dbshell`

Within the shell:

- **List tables** `.tables`
- **Show table contents** `.dump table_name`
- **Show table contents** `.dump <table_name>`

### Adding a column

Migrations in Django rely on inferring differences between your model definitions and table schemas. They don’t work particularly well with SQLite (the default database for this project).
Migrations in Django rely on inferring differences between your model definitions and table schemas. They don't work particularly well with SQLite (the default database for this project).

We recommend you nuke and recreate your DB for schema changes:
`rm django/db.sqlite3 && ./django/manage.py makemigrations && ./django/manage.py migrate`

### More information

[Django documentation](https://docs.djangoproject.com/en/1.8/ref/models/fields/)
```
source venv/bin/activate
rm -f ./db.sqlite3
./manage.py makemigrations
./manage.py migrate
```

More information at the [Django documentation](https://docs.djangoproject.com/en/5.1/ref/models/fields/).
Binary file removed django/db.sqlite3
Binary file not shown.
3 changes: 0 additions & 3 deletions django/pyvenv.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions django/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
django==2.2.13
django-cors-headers==2.5.3
Django==5.1.4
django-cors-headers==4.6.0
63 changes: 58 additions & 5 deletions script/django/setup
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
#!/bin/bash

set -e # Exit on any error

echo "Setting up Django minicom app..."

# Change to the django directory
cd django
python3 -m venv .
source ./bin/activate # or .\Scripts\activate on Windows
pip3 install -r requirements.txt
./manage.py makemigrations
./manage.py migrate

# Check if Python 3 is available
if ! command -v python3 &> /dev/null; then
echo "Error: python3 is not installed or not in PATH"
exit 1
fi

# Check Python version (Django 5.1 requires Python 3.10+)
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
python_major=$(python3 -c 'import sys; print(sys.version_info[0])')
python_minor=$(python3 -c 'import sys; print(sys.version_info[1])')

echo "Using Python version: $python_version"

if [ "$python_major" -lt 3 ] || ([ "$python_major" -eq 3 ] && [ "$python_minor" -lt 10 ]); then
echo "Error: Django 5.1 requires Python 3.10 or higher. You have Python $python_version"
exit 1
fi

# Remove existing virtual environment if it exists
if [ -d "venv" ]; then
echo "Removing existing virtual environment..."
rm -rf venv
fi

# Create virtual environment
echo "Creating virtual environment..."
python3 -m venv venv

# Activate virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Upgrade pip to latest version
echo "Upgrading pip..."
pip install --upgrade pip

# Install requirements
echo "Installing requirements..."
pip install -r requirements.txt

# Make migrations
echo "Creating migrations..."
python manage.py makemigrations

# Apply migrations
echo "Applying migrations..."
python manage.py migrate

echo "Django setup completed successfully!"
echo "To activate the virtual environment, run: source django/venv/bin/activate"
echo "To start the development server, run: python django/manage.py runserver"
17 changes: 15 additions & 2 deletions script/django/start
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/bash

source ./django/bin/activate
set -e # Exit on any error

./django/manage.py runserver 3000
echo "Starting Django minicom app..."

# Check if virtual environment exists
if [ ! -d "django/venv" ]; then
echo "Error: Virtual environment not found. Please run script/django/setup first."
exit 1
fi

# Activate virtual environment
source django/venv/bin/activate

# Start Django development server
echo "Starting Django development server on port 3001..."
python django/manage.py runserver 3001