Skip to content

Final project of the codecademy course "Build Python Web Apps with Django". I used this project to learn how to create a Django app from start to finish under time pressure, as preparation for my entry level assessment task.

Notifications You must be signed in to change notification settings

juliaberning/django-delights

Repository files navigation

Django Restaurant App

This Django app helps restaurant employees easily manage ingredient inventory, create menus and recipes with prices, track purchases, and stay informed about low stock levels.

Getting started

Prerequisites

Ensure the following are installed on your system:

  • Git
  • Python 3.10 or higher (tested on 3.13.1)
python --version

Installation

  1. Clone this repository and navigate into the project directory.
git clone <Github-link> && cd <project-directory>
  1. Create and activate a virtual environment:
# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt

How to use

Set up the database

  1. Prepare and apply migrations:
python3 manage.py makemigrations
python3 manage.py migrate
  1. Create a superuser for accessing the admin interface by running the following command and following the instructions:
python3 manage.py createsuperuser

Run the server

Start the server locally:

python3 manage.py runserver

Access the admin interface at: http://127.0.0.1:8000/admin/

Development

Testing

Run unit tests to verify the functionality:

python3 manage.py test

Linting & Formatting

This project uses ruff for linting and formatting.

# Check for linting issues in the current directory:
ruff check . 

# Automatically fix linting issues:
ruff check --fix

# Format all files in the current directory:
ruff format .

Import Sorting

This project uses isort to sort and organize Python imports for better readability and consistency.

# Check for unsorted imports in the current directory:
isort . --check

# Automatically sort and organize imports:
isort .

# Preview changes without applying them:
isort . --diff

Github Actions Workflow

This repository uses GitHub Actions for automation.

Configured workflows:
  • Ruff Linter: Ensures that the code adheres to linting standards.
  • isort: Ensures organized and sorted imports.
  • unittests: Ensures that the code is tested.
Trigger:
  • On every commit push to any branch.

Inspect Database Queries with runscript

The runscript command lets you run an arbitrary set of python commands within the Django context. It offers the same usability and functionality as running a set of commands in shell.

The orm.py script demonstrates Django's ORM interaction with the database and logs raw SQL queries when LOGGING_ENABLED = True, aiding debugging and performance analysis.

python manage.py runscript orm

Optional: Generate a model diagram

You can generate a visual diagram of your models using Django Extensions and Graphviz.

Install the necessary libraries:

pip install django-extensions
brew install graphviz

Add django-extensions to INSTALLED_APPS in settings.py.

INSTALLED_APPS = [
    ...,
    'django_extensions',
]

Add the following to settings.py to enable diagram generation:

GRAPH_MODELS = {
  'all_applications': True,
  'group_models': True,
}

Generate the model diagram as a .dot file:

python3 manage.py graph_models -a --dot -o restaurant_models.dot

Convert the .dot file to an image:

dot -Tpng base_models.dot -o restaurant_models.png

For further information on the model diagram you can read the the django-extensions documentation.

About

Final project of the codecademy course "Build Python Web Apps with Django". I used this project to learn how to create a Django app from start to finish under time pressure, as preparation for my entry level assessment task.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published