Coder Social home page Coder Social logo

todo-example's Introduction

Todo Application

Create, Update, Delete, List todos. Each user could read/update/create/delete own todos.

Tech Stack:

  • Django
  • Django Rest Framework
  • Jquery
  • Bootstrap

Setup

Create environment

python3 -m virtualenv venv

source venv/bin/activate

pip install -r requirements.txt

# Run tests
python manage.py test

# Run server
python manage.py runserver

Default username: admin, password: 12345678

REST API

Click to read!

Obtain Token

curl --location --request POST 'localhost:8000/api/token-auth' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "admin",
    "password": "12345678"
}'
{
    "token": "18bea1824e361bb23a3be447fe97964c03cdd59d"
}

Get list of todos

curl --location --request GET 'http://localhost:8000/api/todos/' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
HTTP/1.1 200 OK
[
    {
        "id": 2,
        "content": "Todo 2",
        "done": true
    },
    {
        "id": 1,
        "content": "Todo 1",
        "done": false
    }
]

Retrieve detail of todo item

curl --location --request GET 'http://localhost:8000/api/todos/1/' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
HTTP/1.1 200 OK
{
    "id": 1,
    "content": "Todo 1",
    "done": false
}

Create a todo item

curl --location --request POST 'http://localhost:8000/api/todos/' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d' \
--header 'Content-Type: application/json' \
--data-raw '{
    "content": "Todo 3",
    "done": false
}'
HTTP/1.1 201 CREATED
{
    "content": "Todo 3",
    "done": false
}

Update existing todo item

curl --location --request PUT 'http://localhost:8000/api/todos/3/' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d' \
--header 'Content-Type: application/json' \
--data-raw '{
    "content": "Todo 3",
    "done": true
}'
HTTP/1.1 200 OK
{
    "id": 3,
    "content": "Todo 3",
    "done": true
}

Delete existing todo item

curl --location --request DELETE 'http://localhost:8000/api/todos/3/' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
HTTP/1.1 204 NO CONTENT
{
    "id": null,
    "content": "Todo 3",
    "done": true
}

Filtering todo items by content

curl --location --request GET 'http://localhost:8000/api/todos/?search=todo' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
[
    {
        "id": 3,
        "content": "Todo 3",
        "done": true
    },
    {
        "id": 2,
        "content": "Todo 2",
        "done": false
    }
]

Filtering todo items by status

curl --location --request GET 'http://localhost:8000/api/todos/?done=false' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
[
    {
        "id": 2,
        "content": "Todo 2",
        "done": false
    }
]

Filtering todo items content and status

curl --location --request GET 'http://localhost:8000/api/todos/?seacrh=todo&done=true' \
--header 'Authorization: Token 18bea1824e361bb23a3be447fe97964c03cdd59d'
[
    {
        "id": 3,
        "content": "Todo 3",
        "done": true
    }
]

User Interface

Click to read!

Login

Default username: admin, password: 12345678 Login via django admin login url than go to index page

Actions:

  • Click Add to create todo item with status Not Completed
  • Click item detail to go item detail.
  • Click Update to update existing todo content or status.
  • Click Delete to delete existing item.
  • Fill Search input, select todo status and click Search to filter todo items on home page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.