-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from NumanIbnMazid/dev
Dev
- Loading branch information
Showing
300 changed files
with
66,811 additions
and
26,451 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# numanibnmazid.com | ||
# nim23.com | ||
|
||
```diff | ||
- [N:B: This site is under construction] | ||
|
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
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
File renamed without changes.
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,73 @@ | ||
from django.contrib import admin | ||
from django.db import models | ||
from blogs.models import BlogCategory,Blog, BlogViewIP, BlogComment | ||
from utils.mixins import CustomModelAdminMixin | ||
from tinymce.widgets import TinyMCE | ||
|
||
|
||
# ---------------------------------------------------- | ||
# *** BlogCategory *** | ||
# ---------------------------------------------------- | ||
|
||
class BlogCategoryAdmin(CustomModelAdminMixin, admin.ModelAdmin): | ||
class Meta: | ||
model = BlogCategory | ||
|
||
admin.site.register(BlogCategory, BlogCategoryAdmin) | ||
|
||
|
||
# ---------------------------------------------------- | ||
# *** Blog *** | ||
# ---------------------------------------------------- | ||
|
||
class BlogAdmin(admin.ModelAdmin): | ||
formfield_overrides = { | ||
models.TextField: {'widget': TinyMCE()}, | ||
} | ||
|
||
list_display = ( | ||
'title', 'category', 'image', 'overview', 'author', 'tags', 'get_reading_time', | ||
'get_total_words', 'status', 'order', 'get_table_of_contents' | ||
) | ||
|
||
def get_reading_time(self, obj): | ||
return obj.get_reading_time() | ||
|
||
get_reading_time.short_description = 'Reading Time' | ||
|
||
def get_total_words(self, obj): | ||
return obj.get_total_words() | ||
|
||
get_total_words.short_description = 'Total Words' | ||
|
||
def get_table_of_contents(self, obj): | ||
return obj.get_table_of_contents() | ||
|
||
get_table_of_contents.short_description = 'Table of Contents' | ||
|
||
class Meta: | ||
model = Blog | ||
|
||
admin.site.register(Blog, BlogAdmin) | ||
|
||
|
||
# ---------------------------------------------------- | ||
# *** BlogViewIP *** | ||
# ---------------------------------------------------- | ||
|
||
class BlogViewIPAdmin(CustomModelAdminMixin, admin.ModelAdmin): | ||
class Meta: | ||
model = BlogViewIP | ||
|
||
admin.site.register(BlogViewIP, BlogViewIPAdmin) | ||
|
||
|
||
# ---------------------------------------------------- | ||
# *** BlogComment *** | ||
# ---------------------------------------------------- | ||
|
||
class BlogCommentAdmin(CustomModelAdminMixin, admin.ModelAdmin): | ||
class Meta: | ||
model = BlogComment | ||
|
||
admin.site.register(BlogComment, BlogCommentAdmin) |
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,5 @@ | ||
from config.router import router | ||
from blogs.api.views import BlogViewset | ||
|
||
|
||
router.register("blogs", BlogViewset, basename="code_snippets") |
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,33 @@ | ||
from rest_framework import serializers | ||
from blogs.models import Blog, BlogCategory | ||
|
||
|
||
class BlogCategorySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = BlogCategory | ||
fields = "__all__" | ||
|
||
|
||
class BlogSerializer(serializers.ModelSerializer): | ||
category = BlogCategorySerializer() | ||
image = serializers.SerializerMethodField() | ||
reading_time = serializers.SerializerMethodField() | ||
total_words = serializers.SerializerMethodField() | ||
table_of_contents = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = Blog | ||
fields = "__all__" | ||
read_only_fields = ("id", "slug", "created_at", "updated_at") | ||
|
||
def get_image(self, obj): | ||
return obj.get_image() | ||
|
||
def get_reading_time(self, obj): | ||
return obj.get_reading_time() | ||
|
||
def get_total_words(self, obj): | ||
return obj.get_total_words() | ||
|
||
def get_table_of_contents(self, obj): | ||
return obj.get_table_of_contents() |
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,27 @@ | ||
from rest_framework import permissions | ||
from rest_framework.viewsets import GenericViewSet | ||
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin | ||
from utils.helpers import custom_response_wrapper | ||
from blogs.models import Blog | ||
from blogs.api.serializers import BlogSerializer | ||
|
||
|
||
@custom_response_wrapper | ||
class BlogViewset(GenericViewSet, ListModelMixin, RetrieveModelMixin): | ||
permission_classes = (permissions.IsAuthenticated,) | ||
queryset = Blog.objects.filter(status="Published") | ||
serializer_class = BlogSerializer | ||
lookup_field = 'slug' | ||
|
||
def get_queryset(self): | ||
queryset = super().get_queryset() | ||
limit = self.request.query_params.get('_limit') | ||
|
||
if limit: | ||
try: | ||
limit = int(limit) | ||
queryset = queryset[:limit] | ||
except ValueError: | ||
pass | ||
|
||
return queryset |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "blogs" |
Oops, something went wrong.