Skip to content

saddarudin-nextgeni/django-blog-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

85 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฐ Django Blogging App

A full-featured Blogging Platform built with Django REST Framework, PostgreSQL, and Docker, featuring JWT authentication, filters, nested comments, Celery background tasks for email notifications, and an admin dashboard with advanced filtering.


๐Ÿš€ Features

๐Ÿ” Authentication

  • JWT-based authentication (Access & Refresh tokens).
  • Token blacklisting & rotation support.
  • Secure login, registration, and logout endpoints.

๐Ÿ“ Blogging System

  • CRUD operations for posts.
  • Only authors can edit or delete their posts.
  • Nested comment system (reply to comments).
  • Like/unlike functionality (one like per user per post).
  • Full-text and partial search using Postgres SearchVector.

๐Ÿ” Filtering and Search

  • Custom PostFilter class using django-filter.

  • Filter posts by:

    • Title
    • Author email
    • Content
    • Date range
    • Likes range
    • Comments range
    • Has comments (boolean)
  • Combined full-text search using q parameter.

  • Admin filters for title, author, date, likes, and comments.

๐Ÿ“จ Email Notifications (Celery + Redis)

  • Uses Celery task queue and Redis as broker.
  • Sends asynchronous email notifications when a user comments on a post.
  • Background processing ensures non-blocking user experience.

โš™๏ธ Admin Panel

  • Custom admin filters and search for posts.
  • Comment and Like management.
  • Inline display of related comments & likes.

๐Ÿณ Dockerized Setup

  • Complete Docker environment for local development.

  • Containers:

    • web โ†’ Django + Gunicorn
    • db โ†’ PostgreSQL
    • redis โ†’ Redis server for Celery
    • worker โ†’ Celery worker
  • Easy setup using docker-compose.


๐Ÿงฑ Tech Stack

Layer Technology
Backend Django, Django REST Framework
Database PostgreSQL
Async Tasks Celery, Redis
Auth JWT (SimpleJWT)
Containerization Docker, Docker Compose
Filtering/Search django-filters, SearchVector (PostgreSQL)
Testing Tools Postman, curl

๐Ÿงฐ Installation & Setup

1๏ธโƒฃ Clone the repository

git clone https://github.com/saddarudin-nextgeni/django-blog-app.git
cd django-blog-app

2๏ธโƒฃ Create .env file

Example environment variables:

SECRET_KEY=your-secret-key
DEBUG=True
DATABASE_NAME=blogdb
DATABASE_USER=bloguser
DATABASE_PASSWORD=blogpassword
DATABASE_HOST=db
DATABASE_PORT=5432
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your_password
EMAIL_USE_TLS=True

3๏ธโƒฃ Run with Docker Compose

docker-compose up --build

It will start:

  • Django API
  • PostgreSQL
  • Redis
  • Celery Worker

4๏ธโƒฃ Run database migrations

docker-compose exec web python manage.py migrate

5๏ธโƒฃ Create superuser

docker-compose exec web python manage.py createsuperuser

๐Ÿ”ฅ API Endpoints

Method Endpoint Description Auth Required
POST /api/auth/register/ Register new user โŒ
POST /api/auth/login/ Obtain JWT token โŒ
POST /api/auth/token/refresh/ Refresh access token โŒ
GET /api/posts/ List all posts (with filters/search) โœ…/โŒ
GET /api/posts/mine/ List posts by logged-in user โœ…
POST /api/posts/create/ Create new post โœ…
GET /api/posts/<id>/ Get post detail (with nested comments) โœ…/โŒ
PUT/PATCH /api/posts/<id>/edit/ Update post (only author) โœ…
DELETE /api/posts/<id>/edit/ Delete post (only author) โœ…
GET/POST /api/posts/<id>/comments/ List/Create comment โœ…
PUT/PATCH/DELETE /api/comments/<id>/edit/ Edit/Delete comment (only author) โœ…

๐Ÿงฎ Filters Usage Examples

1๏ธโƒฃ Basic filters

GET /api/posts/?title=django
GET /api/posts/[email protected]
GET /api/posts/?date_from=2025-10-01&date_to=2025-10-15

2๏ธโƒฃ Range filters

GET /api/posts/?min_likes=5&max_likes=20
GET /api/posts/?min_comments=2

3๏ธโƒฃ Boolean filters

GET /api/posts/?has_comments=true

4๏ธโƒฃ Combined search

GET /api/posts/?q=how to django

๐Ÿ”„ Background Email Notification Example

When a user comments on a post, a Celery task is triggered:

@shared_task
def send_comment_notification(post_id, comment_author):
    post = Post.objects.get(id=post_id)
    subject = f"New comment on your post '{post.title}'"
    message = f"{comment_author} commented on your post."
    send_mail(subject, message, EMAIL_HOST_USER, [post.author.email])

This task runs asynchronously using Redis as the message broker.


๐Ÿง  Key Concepts Implemented

  • Custom Permissions: IsAuthorOrReadOnly to restrict edit/delete.
  • Django Filters for range/date/boolean filtering.
  • SearchVector + SearchRank for full-text search.
  • Celery tasks for non-blocking email notifications.
  • Custom Admin filters and UI enhancements.
  • Dockerized environment for easy deployment.

๐Ÿง‘โ€๐Ÿ’ป Development Commands

# Run Celery Worker
docker-compose exec web celery -A core worker -l info

# Run Django Shell
docker-compose exec web python manage.py shell

# Collect static files (if needed)
docker-compose exec web python manage.py collectstatic

๐Ÿงฉ Project Structure

blog_project/
โ”‚
โ”œโ”€โ”€ blog/                      # Main app
โ”‚   โ”œโ”€โ”€ models.py              # Post, Comment, Like models
โ”‚   โ”œโ”€โ”€ serializers.py         # DRF serializers
โ”‚   โ”œโ”€โ”€ views.py               # API endpoints
โ”‚   โ”œโ”€โ”€ filters.py             # Custom filters
โ”‚   โ”œโ”€โ”€ tasks.py               # Celery tasks for email
โ”‚   โ”œโ”€โ”€ admin.py               # Admin filters
โ”‚   โ”œโ”€โ”€ urls.py                # API routes
โ”‚
โ”œโ”€โ”€ users/                     # Custom user model & auth
โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ”œโ”€โ”€ serializers.py
โ”‚   โ”œโ”€โ”€ views.py
โ”‚
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ settings.py
โ”‚   โ”œโ”€โ”€ celery.py
โ”‚   โ”œโ”€โ”€ urls.py
โ”‚
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

About

This repository contains code of blog app made in django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published