An open API service indexing awesome lists of open source software.

https://github.com/averageencoreenjoer/tree-menu-project

Django application for creating, managing and displaying tree menus with strict requirements for performance and functionality. The solution is ideal for sites with multi-level navigation, complex structural menus and a requirement for minimal database load.
https://github.com/averageencoreenjoer/tree-menu-project

bootstrap5 ci-cd django django-templates django-test-framework docker docker-compose github-actions gunicorn postgresql python3 sqlite whitenoise

Last synced: 2 months ago
JSON representation

Django application for creating, managing and displaying tree menus with strict requirements for performance and functionality. The solution is ideal for sites with multi-level navigation, complex structural menus and a requirement for minimal database load.

Awesome Lists containing this project

README

          

# ๐ŸŒณ Tree Menu Django Application

[![Django Version](https://img.shields.io/badge/Django-5.2-green)](https://www.djangoproject.com/)
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-13-blue)](https://www.postgresql.org/)
[![Docker](https://img.shields.io/badge/Docker-Compose-orange)](https://www.docker.com/)

This Django application provides functionality for creating and displaying tree menus with compliance with the following requirements:

- The menu is implemented via template tag
- Automatic expansion of the active menu branch
- Storing the menu structure in the database
- Editing via the standard Django admin panel
- Determining the active item by the URL of the current page
- Support for multiple independent menus on one page
- Minimum number of queries to the database (exactly 1 query per menu)

## ๐Ÿš€ Features

- **๐ŸŒณ Recursive menu** - automatic construction of a tree structure
- **โšก๏ธ Optimized queries** - only 1 SQL query for rendering the menu
- **๐Ÿงฉ Simple integration** - adding a menu via template tag
- **๐ŸŽ› Admin panel** - convenient management of the menu structure
- **๐Ÿ“ฑ Adaptive design** - Bootstrap 5 for displaying the menu
- **๐Ÿณ Docker containerization** - quick launch in an isolated environment

## ๐Ÿ“ฆ Installation

### With Docker (recommended)

1. Clone the repository:
```bash
git clone https://github.com/yourusername/tree-menu-app.git
cd tree-menu-app
```

2. Build and run the containers:
```bash
docker-compose up --build
```

3. Apply database migrations:
```bash
docker-compose exec web python manage.py migrate
```

4. Create a superuser:
```bash
docker-compose exec web python manage.py createsuperuser
```

5. The application will be available at: [http://localhost:8000](http://localhost:8000)

### Without Docker

1. Install dependencies:
```bash
pip install -r requirements.txt
```

2. Set up the database in `tree_menu_project/settings.py`

3. Apply migrations:
```bash
python manage.py migrate
```

4. Create a superuser:
```bash
python manage.py createsuperuser
```

5. Run the development server:
```bash
python manage.py runserver
```

## ๐Ÿ›  Usage

1. Go to the admin panel: [http://localhost:8000/admin/](http://localhost:8000/admin/)
2. Create a menu, specifying a unique name
3. Add menu items, setting parents if necessary
4. In the Django template, add:

```django
{% load menu_tags %}

{# Render the menu by name #}
{% draw_menu 'main_menu' %}
```

## ๐Ÿงช Testing

To run tests, run:

```bash
docker-compose exec web python manage.py test menu
```

Or without Docker:

```bash
python manage.py test menu
```

Test coverage:
- Models
- Admin panel
- Template tags
- Menu display logic

## ๐Ÿ—„ Project structure

```
tree_menu_app/
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ manage.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ menu/
โ”‚ โ”œโ”€โ”€ admin.py
โ”‚ โ”œโ”€โ”€ apps.py
โ”‚ โ”œโ”€โ”€ migrations/
โ”‚ โ”œโ”€โ”€ models.py
โ”‚ โ”œโ”€โ”€ templatetags/
โ”‚ โ”œโ”€โ”€ templates/
โ”‚ โ”‚ โ””โ”€โ”€ menu/
โ”‚ โ”‚ โ””โ”€โ”€ menu_template.html
โ”‚ โ””โ”€โ”€ tests.py
โ””โ”€โ”€ tree_menu_project/
โ”œโ”€โ”€ settings.py
โ”œโ”€โ”€ urls.py
โ””โ”€โ”€ wsgi.py
```