Skip to content

Commit

Permalink
Merge pull request #142 from balogun14/balogun14/issue16
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
debrajrout authored Oct 17, 2023
2 parents 5430fcd + 7969603 commit 1609833
Show file tree
Hide file tree
Showing 49 changed files with 577 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv/
DjangoBlog/db.sqlite3
DjangoBlog/Accounts/migrations/
DjangoBlog/BlogPost/migrations/
Empty file added DjangoBlog/Accounts/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added DjangoBlog/Accounts/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added DjangoBlog/Accounts/__pycache__/urls.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions DjangoBlog/Accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions DjangoBlog/Accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Accounts'
Binary file not shown.
3 changes: 3 additions & 0 deletions DjangoBlog/Accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions DjangoBlog/Accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
5 changes: 5 additions & 0 deletions DjangoBlog/Accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.urls import path

urlpatterns = [

]
3 changes: 3 additions & 0 deletions DjangoBlog/Accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file added DjangoBlog/BlogPost/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added DjangoBlog/BlogPost/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added DjangoBlog/BlogPost/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions DjangoBlog/BlogPost/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin

# Register your models here.
from .models import BlogPost

admin.site.register(BlogPost)
6 changes: 6 additions & 0 deletions DjangoBlog/BlogPost/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogpostConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'BlogPost'
24 changes: 24 additions & 0 deletions DjangoBlog/BlogPost/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.5 on 2023-10-05 13:28

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='BlogPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_created=True, auto_now=True)),
('title', models.CharField(max_length=500)),
('body', models.TextField()),
('image', models.ImageField(upload_to='images/')),
],
),
]
Binary file not shown.
23 changes: 23 additions & 0 deletions DjangoBlog/BlogPost/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.utils import timezone
from django.db import models

# Create your models here.


class BlogPost(models.Model):
class PostCategory(models.TextChoices):
Food = "Food", "Food"
Airtificial_intelligence = "Airtificial intelligence", "Ai"
technology = "Technology", "tech"
home = "Home", "Home"

title = models.CharField(max_length=500)
published_date = models.DateTimeField(default=timezone.now)
body = models.TextField()
blogType = models.CharField(
choices=PostCategory.choices, max_length=100, default=PostCategory.home
)
picture = models.ImageField(upload_to="images")

def __str__(self):
return self.title
3 changes: 3 additions & 0 deletions DjangoBlog/BlogPost/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions DjangoBlog/BlogPost/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path

from .views import HomeListView, TechnologyListView, AiListView, FoodListView

urlpatterns = [
path("", HomeListView.as_view(), name="home"),
path("technology/", TechnologyListView.as_view(), name="technology"),
path("ai/", AiListView.as_view(), name="ai"),
path("food/", FoodListView.as_view(), name="food"), # noqa: F405
]
36 changes: 36 additions & 0 deletions DjangoBlog/BlogPost/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.views.generic import (
ListView,
DetailView,
DeleteView,
CreateView,
UpdateView,
)

# from DjangoBlog.BlogPost.models import BlogPost

# Create your views here.

from .models import BlogPost


class HomeListView(ListView):
model = BlogPost
template_name = "home.html"
context_object_name = 'blogPost'


class TechnologyListView(ListView):
model = BlogPost
template_name = "technology.html"


class AiListView(ListView):
model = BlogPost
template_name = "ai.html"
context_object_name = 'AiPost'



class FoodListView(ListView):
model = BlogPost
template_name = "food.html"
Empty file added DjangoBlog/blog/__init__.py
Empty file.
Binary file added DjangoBlog/blog/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added DjangoBlog/blog/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added DjangoBlog/blog/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions DjangoBlog/blog/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for blog project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')

application = get_asgi_application()
133 changes: 133 additions & 0 deletions DjangoBlog/blog/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
Django settings for blog project.
Generated by 'django-admin startproject' using Django 4.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-7iym(@06%_j)9ffu96r4r)b8r0jn08-m(4p9s^x+_m^$*p9j@$"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"crispy_forms",
"crispy_bootstrap5",
"Accounts.apps.AccountsConfig",
"BlogPost.apps.BlogpostConfig",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "blog.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = "blog.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME":
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "/static/"
STATICFILES_DIRS = [BASE_DIR / "static"]

MEDIA_ROOT = os.path.join(BASE_DIR, "images/")
MEDIA_URL = "/images/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
29 changes: 29 additions & 0 deletions DjangoBlog/blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
URL configuration for blog project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("BlogPost.urls")),
path("accounts/", include("Accounts.urls")),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions DjangoBlog/blog/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for blog project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')

application = get_wsgi_application()
Binary file added DjangoBlog/images/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions DjangoBlog/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions DjangoBlog/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### A Simple Blog Project written in Django
-----------------------------------------------------------------------------------------------------
## Author
# Balogun Muhammed-Awwal

-----------------------------------------------------------------------------------------------------

# Stacks Used:
### FrontEnd: HTML,CSS,JAVASCRIPT,BOOTSTRAP,
### Backend: PYTHON3(DJANGO4)
### DataBase: POSTGRESQL
### Hosting: Vercel.com

-----------------------------------------------------------------------------------------------------
### How To Run the Code

### step 1: create a new virtual enviroment using `python3 -m venv .venv `
### step 2: install the requirements from the requirements.txt file using `python3 -m pip install -r requirements.txt `
### step 3: run `python3 manage.py runserver`



Loading

0 comments on commit 1609833

Please sign in to comment.