Back to Projects

Full Stack Blog App

Django • Bootstrap • SQLite

Overview

A complete, fully-featured blog application built with the Django framework. It supports robust user authentication, interactive comment sections on posts, and dynamic tracking of user likes and dislikes. The backend handles complex database relationships and CRUD operations, while the frontend is designed with Bootstrap to deliver a premium, responsive, and cinematic dark-themed content management experience.

Key Code Snippets

Models (models.py)

from django.db import models
from django.contrib.auth.models import User

class Post(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    likes = models.ManyToManyField(User, related_name='post_likes', blank=True)
    dislikes = models.ManyToManyField(User, related_name='post_dislikes', blank=True)

class Comment(models.Model):
    post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    content = models.TextField()

Views (views.py)

from django.shortcuts import render, get_object_or_404
from .models import Post

@login_required
def post_like(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if post.likes.filter(id=request.user.id).exists():
        post.likes.remove(request.user)
    else:
        post.likes.add(request.user)
        if post.dislikes.filter(id=request.user.id).exists():
            post.dislikes.remove(request.user)
    return HttpResponseRedirect(reverse('post_detail', args=[str(pk)]))