Skip to content

Commit 08898a3

Browse files
committed
first commit
0 parents  commit 08898a3

18 files changed

+468
-0
lines changed

.gitignore

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*.py[co]
2+
*.pyj-cached
3+
4+
# Packages
5+
*.egg
6+
*.egg-info
7+
dist
8+
persist.db
9+
martd.db
10+
build
11+
eggs
12+
parts
13+
bin
14+
var
15+
sdist
16+
develop-eggs
17+
.installed.cfg
18+
19+
# Installer logs
20+
pip-log.txt
21+
*.log
22+
23+
# Unit test / coverage reports
24+
.coverage
25+
.tox
26+
.log
27+
.idea
28+
.DS_Store
29+
30+
#Translations
31+
*.mo
32+
33+
#Mr Developer
34+
.mr.developer.cfg
35+
36+
#virtual env folder
37+
envproj*
38+
env
39+
proj
40+
.virtualenv
41+
.env
42+
43+
static_root/
44+
media/
45+
46+
# swp files
47+
*.swp
48+
49+
# py.test
50+
*.cache/
51+
*__pycache__/*
52+
53+
# Python files
54+
settings_local.py
55+
static_files/*
56+
migrations/

Apps/Blog/__init__.py

Whitespace-only changes.

Apps/Blog/admin.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.contrib import admin
2+
3+
from .models import Article, ArticleCategory, Comment
4+
5+
6+
@admin.register(ArticleCategory)
7+
class ArticleCategoryAdmin(admin.ModelAdmin):
8+
pass
9+
10+
11+
@admin.register(Article)
12+
class ArticleAdmin(admin.ModelAdmin):
13+
pass
14+
15+
16+
@admin.register(Comment)
17+
class CommentAdmin(admin.ModelAdmin):
18+
pass

Apps/Blog/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
name = 'Blog'

Apps/Blog/forms.py

Whitespace-only changes.

Apps/Blog/models.py

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from django.db import models
2+
from django.conf import settings
3+
from django.urls.base import reverse
4+
5+
from modules.utils import generate_upload_path, create_slug
6+
7+
8+
class BaseAppModel(models.Model):
9+
"""This is the base model for other models. This will provide fields for other models. Hence abstract =
10+
True"""
11+
12+
name = models.CharField('name', max_length=255, db_index=True, null=True, blank=True,
13+
help_text='this field will be used as name for models inheriting from this model')
14+
created_on = models.DateTimeField('created on', auto_now_add=True, auto_now=False)
15+
updated_on = models.DateTimeField('updated on', auto_now_add=False, auto_now=True)
16+
17+
class Meta:
18+
abstract = True
19+
20+
def __str__(self):
21+
return '%s-%s' % (self.id, self.name)
22+
23+
24+
class ArticleCategory(BaseAppModel):
25+
26+
slug = models.SlugField('slug', max_length=50, blank=True, db_index=True)
27+
photo = models.ImageField('photo', null=True, blank=True)
28+
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, db_index=True, on_delete=models.CASCADE)
29+
30+
class Meta:
31+
verbose_name = 'Category'
32+
verbose_name_plural = 'Categories'
33+
db_table = 'article_category'
34+
unique_together = ('name', 'slug',)
35+
36+
def __str__(self):
37+
return '%s - %s' % (self.id, self.name)
38+
39+
@property
40+
def get_absolute_url(self):
41+
return reverse('blogs:category', kwargs={'slug': self.slug})
42+
43+
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
44+
self.slug = create_slug(self.name)
45+
super().save(force_insert=False, force_update=False, using=None,
46+
update_fields=None)
47+
48+
49+
class Article(BaseAppModel):
50+
51+
category = models.ManyToManyField(ArticleCategory, related_name='category', db_index=True,
52+
help_text="Categories mentioned in the article.")
53+
54+
slug = models.CharField('slug', max_length=500, db_index=True, unique=True,
55+
help_text="slug of an article. It should be unique.")
56+
57+
blog = models.TextField(null=True, blank=True)
58+
intro = models.TextField('intro', max_length=500, help_text='Brief of your article in 50-60 words.')
59+
60+
wallpaper = models.ImageField('wallpaper', max_length=300, null=True, blank=True, upload_to=generate_upload_path,
61+
help_text="wallpaper for the article. This image and its thumbnail "
62+
"will be used everywhere.")
63+
64+
published_on = models.DateTimeField('published on', null=True, blank=True,
65+
help_text="date when the article was published.")
66+
published_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="user", db_index=True,
67+
help_text="User who published the article.", on_delete=models.CASCADE)
68+
69+
published = models.BooleanField('published', default=False, db_index=True,
70+
help_text="If an article is published or not. "
71+
"By default an article will be considered as draft.")
72+
73+
class Meta:
74+
verbose_name_plural = "Blog"
75+
verbose_name = "Blogs"
76+
db_table = "articles"
77+
ordering = ['-id']
78+
79+
def __str__(self):
80+
return '%s-%s' % (self.id, self.name)
81+
82+
@property
83+
def get_absolute_url(self):
84+
return reverse('blogs:blog', kwargs={'slug': self.slug})
85+
86+
87+
# Comments model
88+
class Comment(BaseAppModel):
89+
STATUS = (
90+
(1, 'Allowed'),
91+
(2, 'Deleted'),
92+
(3, 'Spam'),
93+
)
94+
comment = models.TextField('comment')
95+
# image = models.FileField(null=True, blank=True, upload_to=generate_comment_upload_path,
96+
# help_text="image for the comment")
97+
98+
article = models.ForeignKey(Article, db_index=True, related_name="comment", on_delete=models.CASCADE)
99+
comment_by = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True, related_name='comment_by',
100+
on_delete=models.CASCADE)
101+
102+
status = models.PositiveIntegerField('status', choices=STATUS, default=1)
103+
is_edited = models.BooleanField('is_edited', default=False)
104+
105+
class Meta:
106+
verbose_name_plural = "Comments"
107+
verbose_name = "Comment"
108+
db_table = "comment"
109+
ordering = ['-created_on']
110+
111+
def __str__(self):
112+
return '%s' % self.comment[0:30]

Apps/Blog/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

Apps/Blog/urls.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django.urls.conf import path
2+
3+
urlpatterns = [
4+
# path('^$', index, name='home'),
5+
# path(r'^blogs/add/$', AddBlog.as_view(), name='add_blog'),
6+
# path(r'^blogs/sanitize/$', sanitize_blog, name='sanitize_blog'),
7+
# path(r'^blogs/upload/$', blog_upload_image, name='upload_blog_image'),
8+
# path(r'^blogs/tags/$', get_tags, name='get_tags'),
9+
10+
# path(r'^blogs/(?P<token>[\w.@+-]+)/edit/$', EditBlog.as_view(), name='blog-edit'),
11+
12+
13+
# path(r'^blogs/(?P<slug>[\w.@+-]+)/$', blog_view, name='blog'),
14+
# path(r'^category/(?P<slug>[\w.@+-]+)/$', category_view, name='category'),
15+
16+
# path(r'^api/comment/$', login_required(submit_comment, login_url=settings.REDIRECT_TO_LOGIN), name='comment'),
17+
# path(r'^api/blog_like/$', login_required(like_article, login_url=settings.REDIRECT_TO_LOGIN), name='blog_like'),
18+
# path(r'^api/comment_like/$', login_required(like_comment, login_url=settings.REDIRECT_TO_LOGIN),
19+
# name='comment_like'),
20+
# path(r'^api/comment_edit/$', login_required(edit_comment, login_url=settings.REDIRECT_TO_LOGIN),
21+
# name='comment_edit'),
22+
# path(r'^api/comment_delete/$', login_required(delete_comment, login_url=settings.REDIRECT_TO_LOGIN),
23+
# name='comment_delete'),
24+
# path(r'^api/comment_spam/$', login_required(spam_comment, login_url=settings.REDIRECT_TO_LOGIN),
25+
# name='comment_delete'),
26+
]

Apps/Blog/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
django blog with DRF

config/__init__.py

Whitespace-only changes.

config/settings.py

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
"""
2+
Django settings for django_blog project.
3+
4+
Generated by 'django-admin startproject' using Django 2.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.2/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
# Quick-start development settings - unsuitable for production
19+
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
20+
21+
# SECURITY WARNING: keep the secret key used in production secret!
22+
SECRET_KEY = 'g$%9#vq+f9om!q*c2x$o5w^+z*61$=#77rmyr^4t&o_2b1gy32'
23+
24+
# SECURITY WARNING: don't run with debug turned on in production!
25+
DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
# Application definition
30+
31+
INSTALLED_APPS = [
32+
'django.contrib.admin',
33+
'django.contrib.auth',
34+
'django.contrib.contenttypes',
35+
'django.contrib.sessions',
36+
'django.contrib.messages',
37+
'django.contrib.staticfiles',
38+
'Apps.Blog',
39+
'rest_framework',
40+
'debug_toolbar',
41+
]
42+
43+
MIDDLEWARE = [
44+
'debug_toolbar.middleware.DebugToolbarMiddleware',
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.messages.middleware.MessageMiddleware',
51+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
]
53+
54+
ROOT_URLCONF = 'config.urls'
55+
56+
# Debug toolbar
57+
INTERNAL_IPS = [
58+
'127.0.0.1',
59+
]
60+
61+
TEMPLATES = [
62+
{
63+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
64+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
65+
'APP_DIRS': True,
66+
'OPTIONS': {
67+
'context_processors': [
68+
'django.template.context_processors.debug',
69+
'django.template.context_processors.request',
70+
'django.contrib.auth.context_processors.auth',
71+
'django.contrib.messages.context_processors.messages',
72+
],
73+
},
74+
},
75+
]
76+
77+
WSGI_APPLICATION = 'config.wsgi.application'
78+
79+
# REST Framework settings
80+
REST_FRAMEWORK = {
81+
'DEFAULT_AUTHENTICATION_CLASSES': (
82+
'rest_framework.authentication.BasicAuthentication',
83+
'rest_framework.authentication.SessionAuthentication',
84+
),
85+
'DEFAULT_PERMISSION_CLASSES': [
86+
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
87+
]
88+
89+
}
90+
91+
# Database
92+
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
93+
94+
DATABASES = {
95+
'default': {
96+
'ENGINE': 'django.db.backends.sqlite3',
97+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
98+
}
99+
}
100+
101+
# Password validation
102+
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
103+
104+
AUTH_PASSWORD_VALIDATORS = [
105+
{
106+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
107+
},
108+
{
109+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
110+
},
111+
{
112+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
113+
},
114+
{
115+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
116+
},
117+
]
118+
119+
# Internationalization
120+
# https://docs.djangoproject.com/en/2.2/topics/i18n/
121+
122+
LANGUAGE_CODE = 'en-us'
123+
124+
TIME_ZONE = 'UTC'
125+
126+
USE_I18N = True
127+
128+
USE_L10N = True
129+
130+
USE_TZ = True
131+
132+
# Static files (CSS, JavaScript, Images)
133+
# https://docs.djangoproject.com/en/2.2/howto/static-files/
134+
135+
136+
MEDIA_URL = '/media/'
137+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
138+
139+
STATIC_URL = '/static/'
140+
141+
STATICFILES_FINDERS = (
142+
'django.contrib.staticfiles.finders.FileSystemFinder',
143+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
144+
)
145+
146+
STATICFILES_DIRS = (
147+
os.path.join(BASE_DIR, 'static'),
148+
)

0 commit comments

Comments
 (0)