Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Django version 3 and adding tagging functionality to particular post #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Django_blog.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"compile-hero.disable-compile-files-on-did-save-code": true
}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

A blog application made on Django.

## To run this project follow these steps:
```javascript
git clone https://github.com/TheAbhijeet/Django_blog.git
```
```python
pip install -r requirements.txt
```
```python
python manage.py migrate
```
```python
python manage.py runserver
```

### To add blog posts first create superuser account and write from django admin panel(http://127.0.0.1:8000/admin)
```python
python manage.py createsuperuser
```

![ezgif com-video-to-gif](https://user-images.githubusercontent.com/38559396/55287491-12c4de80-53c7-11e9-8c6a-3f02b79ba9ca.gif)

**Release 1.0** -Blog application made with Django, To learn more read https://djangocentral.com/building-a-blog-application-with-django
Expand Down
4 changes: 3 additions & 1 deletion blog/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib import admin
from .models import Post, Comment
from .models import Post, Comment,contactmessage

from django_summernote.admin import SummernoteModelAdmin


class PostAdmin(SummernoteModelAdmin):
list_display = ('title', 'slug', 'status', 'created_on')
list_filter = ('status', 'created_on')
Expand All @@ -24,3 +25,4 @@ def approve_comments(self, request, queryset):


admin.site.register(Post, PostAdmin)
admin.site.register(contactmessage)
20 changes: 20 additions & 0 deletions blog/migrations/0005_comment_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.0.3 on 2020-10-07 08:06

from django.db import migrations
import taggit.managers


class Migration(migrations.Migration):

dependencies = [
('taggit', '0003_taggeditem_add_unique_index'),
('blog', '0004_auto_20191015_0853'),
]

operations = [
migrations.AddField(
model_name='comment',
name='tags',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
),
]
24 changes: 24 additions & 0 deletions blog/migrations/0006_auto_20201007_1355.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.3 on 2020-10-07 08:10

from django.db import migrations
import taggit.managers


class Migration(migrations.Migration):

dependencies = [
('taggit', '0003_taggeditem_add_unique_index'),
('blog', '0005_comment_tags'),
]

operations = [
migrations.RemoveField(
model_name='comment',
name='tags',
),
migrations.AddField(
model_name='post',
name='tags',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
),
]
21 changes: 21 additions & 0 deletions blog/migrations/0007_contactmessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.0.3 on 2020-10-09 00:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0006_auto_20201007_1355'),
]

operations = [
migrations.CreateModel(
name='contactmessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('message', models.CharField(max_length=5550)),
],
),
]
18 changes: 18 additions & 0 deletions blog/migrations/0008_auto_20201009_0328.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.3 on 2020-10-09 00:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0007_contactmessage'),
]

operations = [
migrations.AlterField(
model_name='contactmessage',
name='message',
field=models.TextField(max_length=5550),
),
]
11 changes: 10 additions & 1 deletion blog/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.contrib.auth.models import User

from taggit.managers import TaggableManager

STATUS = ((0, "Draft"), (1, "Publish"))

Expand All @@ -13,6 +13,7 @@ class Post(models.Model):
)
updated_on = models.DateTimeField(auto_now=True)
content = models.TextField()
tags = TaggableManager()
created_on = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=STATUS, default=0)

Expand Down Expand Up @@ -41,3 +42,11 @@ class Meta:

def __str__(self):
return "Comment {} by {}".format(self.body, self.name)


class contactmessage(models.Model):
email = models.EmailField(max_length=254)
message = models.TextField(max_length=5550)

def __str__(self):
return self.email
1 change: 1 addition & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

urlpatterns = [
path("feed/rss", LatestPostsFeed(), name="post_feed"),
path("conact/",views.contact,name="contact"),
path("feed/atom", AtomSiteNewsFeed()),
path("", views.PostList.as_view(), name="home"),
# path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
Expand Down
14 changes: 12 additions & 2 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.views import generic
from .models import Post
from .models import Post,contactmessage
from .forms import CommentForm
from django.shortcuts import render, get_object_or_404
from django.shortcuts import render, get_object_or_404,redirect



class PostList(generic.ListView):
Expand Down Expand Up @@ -45,3 +46,12 @@ def post_detail(request, slug):
},
)

def contact(request):
if request.method == "POST":
email = request.POST['email']
message = request.POST['message']
newmage = contactmessage(email=email,message=message)
newmage.save()
return redirect("/")
context = {}
return render(request,'contact.html',context)
32 changes: 9 additions & 23 deletions mysite/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 2.1.7.
Generated by 'django-admin startproject' using Django 3.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
Expand All @@ -16,9 +16,8 @@
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0x!b#(1*cd73w$&azzc6p+essg7v=g80ls#z&xcx*mpemx&@9$'
Expand All @@ -28,7 +27,6 @@

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -38,14 +36,13 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'django.contrib.sitemaps',
'taggit',
'blog',
'crispy_forms',
'django_summernote',
]

INSTALLED_APPS += ( 'django.contrib.sitemaps',)

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down Expand Up @@ -76,7 +73,6 @@

WSGI_APPLICATION = 'mysite.wsgi.application'


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

Expand All @@ -87,7 +83,6 @@
}
}


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

Expand All @@ -106,7 +101,6 @@
},
]


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

Expand All @@ -120,7 +114,6 @@

USE_TZ = True


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

Expand All @@ -129,23 +122,16 @@
# Location of static files
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]


STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')







STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

CRISPY_TEMPLATE_PACK = 'bootstrap4'


# Media paths

# Base url to serve media files
MEDIA_URL = '/media/'

# Path where media is stored
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

X_FRAME_OPTIONS = 'SAMEORIGIN'
2 changes: 1 addition & 1 deletion mysite/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
Expand Down
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
asgiref==3.2.10
certifi==2020.6.20
Django==3.0.3
django-crispy-forms==1.9.2
django-summernote==0.8.11.6
django-taggit==1.3.0
pytz==2020.1
sqlparse==0.3.1
wincertstore==0.2
6 changes: 0 additions & 6 deletions requirments.txt

This file was deleted.

11 changes: 11 additions & 0 deletions static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ body {

.card {
box-shadow: 0 16px 48px #E3E7EB;
}



/* contact page */
.contact-message{
margin-top: 30px;
align-items: center;
}
.message-form{
margin: 0 auto;
}
Loading