Skip to content

Django Music Application, created with django and postgresql

Notifications You must be signed in to change notification settings

mustafausama/djmusic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django application for managing artists and their related albums

Index

Demo application

Demo application has the second part only

Final application is deplyed on heroku Admin Link

username: admin
password: pass1234

Results documentation

The development steps and their results are documented in the file RESULTS.md

App installation

Prerequites

You should have the following installed in order to run the application:

  • Python
  • Poetry
  • PostgreSQL (local or remote)

Clone

Run the following terminal command in order to clone the app and go into its directory.

git clone https://gitlab.com/mustafa.abdelrahman/django-training.git && cd django-training

Virtual Environment

While in the root directory (django-training), run the following command to use the poetry environment

poetry shell

Or you can list all the available virtual environments with the command poetry env list --full-path, then copy the path of the virtual environment you want to use and run the following command with the path instead of /full/path/to/python

poetry env use /full/path/to/python

Install

Run the following terminal command in order to install the app

poetry install

Configurations

In djmusic directory, change the name of the .env.example file to .env
Fill the .env file with the database credentails, and the secret key of the app.

You can generate a secret key with either of the following commands

openssl rand -base64 32
head -c 32 /dev/urandom | base64

To be safe, store the secret key in the .env file inside the quotations marks.

Migrations

In the root (django-training) directory. Run the following code to prepare the database migrations

poetry run python djmusic/manage.py makemigrations

Then run the following command to apply the migrations

poetry run python djmusic/manage.py migrate

Create a superuser

In order to create a super user, run the following command and enter the credentials interactively

poetry run python djmusic/manage.py createsuperuser

Running tests

In order to run the created endpoint tests, run the following command

poetry run pytest

A message with the testing result, percentage, passing tests, and time will be printed.

Running the server

Run the following comman to start serving the application

poetry run python djmusic/manage.py runserver

If port 8000 is busy, try running on another port of your choice as follows

poetry run python djmusic/manage.py runserver 8080

You can replace 8080 with the port you wish.

Now visit http://localhost:8000 or http://localhost:8080 or replace 8000 with the port you have specified while running the server

You can visit the admin panel using this link http://localhost:8000/admin Now you can login using the credentials you created in the previous section

App Usage

Creating Artists and Albums

These Views do not work anymore after the sixth part

Artists and albums can be created using the following links, repectively.

Artist: http://localhost:8000/artists/create/

Starting with the fifth part, the artist's view endpoints are followed by /old/ because a serialized REST API view was linked to the original endpoint
List View: http://localhost:8000/artists/old/create/

Album: http://localhost:8000/albums/create/

Artist list view

These Views do not work anymore after the sixth part

A list view of the artists and their respective albums can be viewed using the following link.

List View: http://localhost:8000/artists/

Starting with the fifth part, the artist's view endpoints are followed by /old/ because a serialized REST API view was linked to the original endpoint
List View: http://localhost:8000/artists/old/

Login and logout

This View does not work anymore after the sixth part

Using the following links, you can:

REST API

Two rest-api endpoints were added to the application.

  • Artist View (JSON): GET http://localhost:8000/artists/
    Data will be returned in the following format

    [
        {
            "id": '<id>', // Numeric
            "stage_name": "<stage_name>", // String
            "social_link": "<social_link>" // String
        },
        ...
    ]
  • Artist Creation (JSON body): POST http://localhost:8000/artists/

    Requires authentication as Basic Authentication (username and password) along with the request

    Requires a body with the following keys

    • stage_name: required, unique, max length of 200 characters
    • social_link: optional

    Data will be returned in the following format

    {
        "id": '<id>', // Numeric
        "stage_name": "<stage_name>", // String
        "social_link": "<social_link>" // String
    }

Authentication

  • Register: POST http://localhost:8000/authentication/register/
    It accepts a body with the following fields

    • username: required, unique
    • email: optional, unique
    • password1: require, strong password
    • password2: matches password1

    It returns a json with the following format

    {
      "username": "<username>",
      "email": "<email>"
    }
  • Login: POST http://localhost:8000/authentication/#/
    It accepts a body with the following fields

    • username: required
    • password: required

    It returns a json with the following format

    {
      "token": "<knox token>",
      "user": {
        "id": '<id>', // Numeric
        "username": "<username>",
        "email": "<email>",
        "bio": "<bio>"
      }
    }
  • Logout: POST http://localhost:8000/authentication/logout/
    It requires an authorization header with in the following format

    Authorization: Token token_here

User Details API

  • Retrieve User: GET http://localhost:8000/users/int:pk/
    It returns a json with the following format

    {
      "id": '<id>',
      "username": "<username>",
      "email": "<email>",
      "bio": "<bio>"
    }
  • Update the whole user: PUT http://localhost:8000/authentication/#/

    It accepts a body with the following required fields

    • username: required

    It accepts a body with the following optional fields

    • email
    • bio

    It requires an authorization header with in the following format

    Authorization: Token token_here

    It returns a json with the following format

    {
      "id": '<id>',
      "username": "<username>",
      "email": "<email>",
      "bio": "<bio>"
    }
  • Update specific user fields: PUT http://localhost:8000/authentication/#/ It accepts a body with any (or all) the following optional fields

    • username
    • email
    • bio

    It requires an authorization header with in the following format

    Authorization: Token token_here

    It returns a json with the following format

    {
      "id": '<id>',
      "username": "<username>",
      "email": "<email>",
      "bio": "<bio>"
    }

About

Django Music Application, created with django and postgresql

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published