Skip to content

Commit

Permalink
重构Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
nffish committed Feb 24, 2018
1 parent 928b294 commit b25dd1e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 29 deletions.
6 changes: 3 additions & 3 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib import admin
from .models import BlogArticles
from .models import Article


class BlogArticlesAdmin(admin.ModelAdmin):
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'publish',)
list_filter = ('publish', 'author',)
search_fields = ('title', 'body',)
Expand All @@ -11,4 +11,4 @@ class BlogArticlesAdmin(admin.ModelAdmin):
ordering = ['publish', 'author']


admin.site.register(BlogArticles, BlogArticlesAdmin)
admin.site.register(Article, ArticleAdmin)
6 changes: 3 additions & 3 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from django.contrib.auth.models import User


class BlogArticles(models.Model):
title = models.CharField(max_length=300)
class Article(models.Model):
title = models.CharField(max_length=300, default='Title')
author = models.ForeignKey(User, related_name="blog_posts")
body = models.TextField()
content = models.TextField(null=True)
publish = models.DateTimeField(default=timezone.now)

class Meta:
Expand Down
17 changes: 0 additions & 17 deletions blog/templates/base.html

This file was deleted.

15 changes: 15 additions & 0 deletions blog/templates/blog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% for article in articles %}
<h1>{{ article.title }}</h1>
<p>{{ article.author }} {{ article.publish }}</p>
<h3>{{ article.content }}</h3>
<br/>
{% endfor %}
</body>
</html>
4 changes: 3 additions & 1 deletion blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

app_name = 'blog'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index')
url(r'^$', views.index),
url(r'^index/', views.index),

]
9 changes: 5 additions & 4 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.shortcuts import render
from .models import BlogArticles
from .models import Article
from django.http import HttpResponse


def blog_title(request):
articles = BlogArticles.objects.all()
return render(request, 'blog/titles.html', {'blog': articles})
def index(request):
articles = Article.objects.all()
return render(request, 'blog/index.html', {'articles': articles})
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'UTC'

Expand Down
1 change: 1 addition & 0 deletions mysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.contrib import admin

urlpatterns = [
url(r'^$', include('blog.urls', namespace='blog')),
url(r'^blog/', include('blog.urls', namespace='blog')),
url(r'^polls/', include('polls.urls', namespace='polls')),
url(r'^admin/', admin.site.urls),
Expand Down

0 comments on commit b25dd1e

Please sign in to comment.