Skip to content

🎵 Simple Django app: 2 models in a many-to-many relationship added to admin panel. Wrote tests, used in-memory DB, created CI/CD pipeline with Docker and Heroku in it.

Notifications You must be signed in to change notification settings

BSski/django-music

Repository files navigation

DjangoMusic

Build Status Maintainability CodeFactor codecov Code style: black

🎆 Live demo 🎆

[Heroku retracted its free tier, therefore all my demos are unavailable until further notice.]

Table of contents

📜 Project description

This is a recruitment task for a Junior Python Developer position. The task was simple: to create a Django admin-panel-only website, with two models (Author, Song) with a many-to-many relationship between them, along with viewing and creating instances of those models in the admin panel.

The database choice was arbitrary, but with a recommendation of an in-memory version. While I believe it would make the task easier in for example Java's Spring, in Django it doesn't. I decided to take the challenge and try to run Django with an in-memory database only, and I succeeded. Every time the server is shut down, created model instances are wiped. Every time the server is started, migrations are run and the admin account is created automatically. I do realise that it is a nonstandard solution, but I still wanted to try that, since the rest of the task was straightforward.

Besides that, I implemented automated testing in a CI/CD pipeline on SemaphoreCI, along with dockerization and deployment from a container to Heroku.

🔨 Technologies used

  • Python 3.9.12
  • Django 4.0.5
  • Gunicorn 20.1.0
  • Docker
  • SemaphoreCI
  • Heroku

🛠️ Deployment

A) through Docker:

  1. Create an .env file basing on .env_sample_file from the repository.
  2. Run docker run --env-file .env -p 8020:8020 bsski/django-music:latest in the .env file directory.
  3. Access localhost:8020.

B) without Docker:

  1. Download the repository.
  2. Create a virtual environment.
  3. Run pip install -r requirements.txt in the directory of requirements.txt.
  4. Create an .env file basing on .env_sample_file from the repository in the directory of .env_sample_file.
  5. Run python manage.py runserver --noreload in the directory of manage.py.
  6. Access 127.0.0.1:8000.

The admin panel can be found under your chosen URL or, if you didn't set it in the .env file, the default /hidden_admin_url. Security through obscurity is not enough of course, but I find it a nice complementary solution.

🔐 Environment variables

To run this project, you have to set up the following environment variables in the .env file (the values below are exemplary):

DJANGO_SUPERUSER_PASSWORD=TestAdminPassword
DJANGO_SUPERUSER_USERNAME=TestAdminName
DJANGO_SUPERUSER_EMAIL=TestAdmin@email.com
SECRET_KEY=TestSecretKey
ADMIN_LOGIN_URL=test_admin_login_url
PORT=8020

🚀 Features

  • two models in a many-to-many relationship (Author, Song),
  • django admin panel which enables creating instances of models and viewing them,
  • purely in-memory database.

Furthermore, the website is deployed on Heroku from a Docker image using a CI/CD SemaphoreCI pipeline:

CI/CD screenshot

⬆️ Room for improvement

Room for improvement:

  • QoL features in admin panel could be added, for example sorting.

👷 Author

About

🎵 Simple Django app: 2 models in a many-to-many relationship added to admin panel. Wrote tests, used in-memory DB, created CI/CD pipeline with Docker and Heroku in it.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages