change timezone , make simple post pages and change view and url files

This commit is contained in:
mohamad24xx 2024-08-30 03:45:09 +03:30
parent 823d724167
commit fbd2116921
9 changed files with 63 additions and 6 deletions

View file

@ -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)

View 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',
),
]

View file

@ -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')

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>My Blog</title>
</head>
<body>
<h1>My Blog</h1>
{% block content %}
{% endblock %}
</body>
</html>

View 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 %}

View 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 %}

View file

@ -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})

View file

@ -106,7 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Tehran'
USE_I18N = True

View file

@ -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'),
]