This project presents a RESTful Time Tracking API with support for multiple users and projects. It is implemented using Django and Django Rest Framework!
This project uses Django with Django Rest Framework, it was written in Python 3.8 but is compabtible with Python 3.9 as well:
git clone https://github.com/WiGeeky/sample-django.git
cd sample-django
python3 -m venv venv
./venv/bin/activate
python -m pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
Navigate to 127.0.0.1:8000/api/v1 for a DRF-generated document of the APIs:
Note: the
/api/v1/users
path is only available during debugging as this app isn't supposed to provide an interface for users.
There are three main entities in this project: Users, Projects, and TimeLogs. The User entity is contrib.auth's User model.
Projects are entities that act as categories in time tracking. See the schema below:
CREATE TABLE "time_tracker_project" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" text NOT NULL, "slug" varchar(50) NOT NULL
);
CREATE TABLE "time_tracker_project_users" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"project_id" bigint NOT NULL REFERENCES "time_tracker_project" ("id") DEFERRABLE INITIALLY DEFERRED,
"user_id" integer NOT NULL REFERENCES
"auth_user" ("id") DEFERRABLE INITIALLY DEFERRED
);
TimeLogs are the main entity of the time tracking project.
CREATE TABLE "time_tracker_timelog" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"start_at" datetime NULL, "finish_at" datetime NULL,
"duration" integer NULL, "project_id" bigint NOT NULL REFERENCES "time_tracker_project" ("id") DEFERRABLE INITIALLY DEFERRED,
"user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED
);
Timelogs also have a computed status value which is:
- A Timelog with both
start_at
andduration
set to null is considered INVALID - A Timelog with NOT NULL
duration
is considered FINISHED - A Timelog with NULL
duration
and NOT NULLstart_at
and NOT NULLfinish_at
is considered FINISHED - A Timelog with NULL
duration
and NULLfinish_at
is considered ONGOING