-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add blog app and document API endpoints * blog app added * blog app added * moved blog into apps * fixes * .venv * refactoring blog app * blog urls and ins * adding missing routes * models inheriting from BaseModel * added fileds to serializers * renamed file correctly * migrations --------- Co-authored-by: saahndongransom <saahndongransom@gmail.com>
- Loading branch information
1 parent
2a539e6
commit 7f68f89
Showing
45 changed files
with
659 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ Closes #23 | |
## Screenshots | ||
|
||
(Insert image, only for frontend) | ||
Bearer d855f89533088ce049754df15432f411 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
# Ignore the virtual environment | ||
venv/ | ||
.venv | ||
|
||
# Ignore the Django secret key | ||
secret_key.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.contrib import admin | ||
from apps.blog.models.tag import Tag | ||
from apps.blog.models.category import Category | ||
from apps.blog.models.author import Author | ||
from apps.blog.models.blog import Blog | ||
from apps.blog.models.image import Image | ||
|
||
admin.site.register(Tag) | ||
admin.site.register(Category) | ||
admin.site.register(Author) | ||
admin.site.register(Blog) | ||
admin.site.register(Image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
# class BlogConfig(AppConfig): | ||
# default_auto_field = 'django.db.models.BigAutoField' | ||
# name = 'blog' | ||
|
||
|
||
|
||
class BlogConfig(AppConfig): | ||
name = 'apps.blog' | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
|
||
def ready(self): | ||
import apps.blog.signals | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 5.0.1 on 2024-06-05 23:50 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Author', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('bio', models.TextField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Blog', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200)), | ||
('content', models.TextField()), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.author')), | ||
('categories', models.ManyToManyField(to='blog.category')), | ||
('tags', models.ManyToManyField(to='blog.tag')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Image', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('image_file', models.ImageField(upload_to='images/')), | ||
('uploaded_at', models.DateTimeField(auto_now_add=True)), | ||
('blog_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='blog.blog')), | ||
], | ||
), | ||
] |
162 changes: 162 additions & 0 deletions
162
apps/blog/migrations/0002_author_active_author_created_at_author_created_by_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# Generated by Django 5.0.1 on 2024-10-04 08:17 | ||
|
||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import utils.main | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='author', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='author', | ||
name='created_at', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='author', | ||
name='created_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='author', | ||
name='updated_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
migrations.AddField( | ||
model_name='author', | ||
name='updated_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='blog', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='blog', | ||
name='created_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='blog', | ||
name='updated_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='category', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='category', | ||
name='created_at', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='category', | ||
name='created_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='category', | ||
name='updated_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
migrations.AddField( | ||
model_name='category', | ||
name='updated_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='image', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='image', | ||
name='created_at', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='image', | ||
name='created_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='image', | ||
name='updated_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
migrations.AddField( | ||
model_name='image', | ||
name='updated_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='created_at', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='created_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='updated_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='updated_by', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_%(class)s_set', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AlterField( | ||
model_name='author', | ||
name='id', | ||
field=models.UUIDField(default=utils.main.generate_uuid, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='blog', | ||
name='id', | ||
field=models.UUIDField(default=utils.main.generate_uuid, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='category', | ||
name='id', | ||
field=models.UUIDField(default=utils.main.generate_uuid, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='image', | ||
name='id', | ||
field=models.UUIDField(default=utils.main.generate_uuid, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='tag', | ||
name='id', | ||
field=models.UUIDField(default=utils.main.generate_uuid, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False), | ||
), | ||
] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
from apps.users.models.base_model import BaseModel | ||
|
||
|
||
|
||
class Author(BaseModel): | ||
name = models.CharField(max_length=100) | ||
bio = models.TextField() | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
from apps.users.models.base_model import BaseModel | ||
from apps.blog.models.author import Author | ||
from apps.blog.models.tag import Tag | ||
from apps.blog.models.category import Category | ||
|
||
class Blog(BaseModel): | ||
title = models.CharField(max_length=200) | ||
content = models.TextField() | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
author = models.ForeignKey(Author, on_delete=models.CASCADE) | ||
categories = models.ManyToManyField(Category) | ||
tags = models.ManyToManyField(Tag) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db import models | ||
from apps.users.models.base_model import BaseModel | ||
|
||
class Category(BaseModel): | ||
name = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.db import models | ||
from apps.users.models.base_model import BaseModel | ||
from apps.blog.models.blog import Blog | ||
|
||
class Image(BaseModel): | ||
image_file = models.ImageField(upload_to='images/') | ||
uploaded_at = models.DateTimeField(auto_now_add=True) | ||
blog_post = models.ForeignKey(Blog, related_name='images', on_delete=models.CASCADE) | ||
|
||
def __str__(self): | ||
return f"Image for {self.blog_post.title}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
from apps.users.models.base_model import BaseModel | ||
|
||
class Tag(BaseModel): | ||
name = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
from rest_framework.permissions import BasePermission, SAFE_METHODS | ||
|
||
class IsAuthorOrReadOnly(BasePermission): | ||
def has_object_permission(self, request, view, obj): | ||
if request.method in SAFE_METHODS: | ||
return True | ||
return obj.author == request.user |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.urls import path | ||
from apps.blog.views.post import PostDetail, PostList | ||
from apps.blog.views.blog import BlogListCreateView | ||
from apps.blog.views.author import AuthorListView | ||
from apps.blog.views.category import CategoryListView | ||
from apps.blog.views.image import ImageListView, ImageCreateView | ||
from apps.blog.views.tag import TagListView | ||
from apps.blog.views.index import index | ||
|
||
|
||
urlpatterns = [ | ||
path('posts/', PostList.as_view(), name='post-list'), | ||
path('posts/<int:pk>/', PostDetail.as_view(), name='post-detail'), | ||
path('posts/create/', BlogListCreateView.as_view(), name='post-create'), | ||
path('authors/', AuthorListView.as_view(), name='author-list'), | ||
path('categories/', CategoryListView.as_view(), name='category-list'), | ||
path('images/', ImageListView.as_view(), name='image-list'), | ||
path('images/create/', ImageCreateView.as_view(), name='image-create'), | ||
path('tags/', TagListView.as_view(), name='tag-list'), | ||
path('', index, name='index'), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from rest_framework import serializers | ||
from apps.blog.models.author import Author | ||
|
||
|
||
class AuthorSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Author | ||
fields = ('id', 'name', 'bio') |
Oops, something went wrong.