change timezone , make simple post pages and change view and url files
This commit is contained in:
parent
823d724167
commit
fbd2116921
|
@ -1,5 +1,5 @@
|
|||
# Register your models here.
|
||||
from django.contrib import admin
|
||||
from .models import MarkdownContent
|
||||
from .models import Post
|
||||
|
||||
admin.site.register(MarkdownContent)
|
||||
admin.site.register(Post)
|
||||
|
|
17
blog/migrations/0003_rename_markdowncontent_post.py
Normal file
17
blog/migrations/0003_rename_markdowncontent_post.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 5.1 on 2024-08-29 23:54
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0002_markdowncontent_author_markdowncontent_created_at_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='MarkdownContent',
|
||||
new_name='post',
|
||||
),
|
||||
]
|
|
@ -2,7 +2,7 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
class MarkdownContent(models.Model):
|
||||
class Post(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
content = models.TextField()
|
||||
author = models.CharField(max_length=100,default='tbd')
|
||||
|
|
12
blog/templates/blog/base.html
Normal file
12
blog/templates/blog/base.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My Blog</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>My Blog</h1>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
9
blog/templates/blog/home.html
Normal file
9
blog/templates/blog/home.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
{% extends 'blog/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
{% for post in posts %}
|
||||
<h2><a href="{% url 'post_detail' post.pk %}">{{ post.title }}</a></h2>
|
||||
<p>{{ post.content|truncatewords:30 }}</p>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
8
blog/templates/blog/post_detail.html
Normal file
8
blog/templates/blog/post_detail.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
{% extends 'blog/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{ post.title }}</h2>
|
||||
<p>{{ post.content }}</p>
|
||||
<p><small>By {{ post.author }} on {{ post.created_at }}</small></p>
|
||||
{% endblock %}
|
|
@ -1,3 +1,11 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from django.shortcuts import render
|
||||
from .models import Post
|
||||
|
||||
def home(request):
|
||||
posts = Post.objects.all()
|
||||
return render(request, 'blog/home.html', {'posts': posts})
|
||||
|
||||
def post_detail(request, pk):
|
||||
post = Post.objects.get(pk=pk)
|
||||
return render(request, 'blog/post_detail.html', {'post': post})
|
||||
|
|
|
@ -106,7 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Asia/Tehran'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
|
|
@ -16,7 +16,10 @@ Including another URLconf
|
|||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from blog import views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', views.home, name='home'),
|
||||
path('post/<int:pk>/', views.post_detail, name='post_detail'),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue