From a64f237e0aec606e95ef5d884a9d255d93de9b18 Mon Sep 17 00:00:00 2001 From: WinWind35 <472981667@qq.com> Date: Mon, 18 Sep 2017 16:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AF=84=E8=AE=BA=E5=92=8C?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=AE=BE=E7=BD=AE=E7=9A=84admin=E3=80=81form?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typeidea/comment/admin.py | 26 +++++++++++++++++++++++++- typeidea/comment/forms.py | 11 +++++++++++ typeidea/config/admin.py | 18 +++++++++++++++++- typeidea/config/forms.py | 16 ++++++++++++++++ typeidea/config/models.py | 1 + 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 typeidea/comment/forms.py create mode 100644 typeidea/config/forms.py diff --git a/typeidea/comment/admin.py b/typeidea/comment/admin.py index 13be29d..7b9db51 100644 --- a/typeidea/comment/admin.py +++ b/typeidea/comment/admin.py @@ -3,4 +3,28 @@ from django.contrib import admin -# Register your models here. +from .models import Comment +from typeidea.custom_site import custom_site + + +@admin.register(Comment,site=custom_site) +class CommentAdmin(admin.ModelAdmin): + list_display = [ + 'post', 'content', 'nickname', 'created_time' + ] + list_filter = ['post', 'nickname'] + search_fields = ['post', 'content', 'nikename'] + save_on_top = True + show_full_result_count = True + + actions_on_top = True + date_hierarchy = 'created_time' + + # 编辑页面 + save_on_top = True + exclude = ('nickname', 'email',) + + def save_model(self, request, obj, form, change): + obj.nickname = request.user + obj.email = request.user.email + return super(CommentAdmin, self).save_model(request, obj, form, change) diff --git a/typeidea/comment/forms.py b/typeidea/comment/forms.py new file mode 100644 index 0000000..b3b9cf5 --- /dev/null +++ b/typeidea/comment/forms.py @@ -0,0 +1,11 @@ +# coding:utf-8 +from __future__ import unicode_literals + +from django import forms + +from .models import Comment + + +class CommentForm(forms.ModelForm): + class Meta: + model = Comment diff --git a/typeidea/config/admin.py b/typeidea/config/admin.py index 13be29d..2c29f08 100644 --- a/typeidea/config/admin.py +++ b/typeidea/config/admin.py @@ -3,4 +3,20 @@ from django.contrib import admin -# Register your models here. +from .models import Link, SideBar +from typeidea.custom_site import custom_site + + +@admin.register(Link, site=custom_site) +class LinkAdmin(admin.ModelAdmin): + list_display = ('title', 'href', 'status', 'created_time',) + list_filter = ('status',) + search_fields = ('title', 'herf',) + + + +@admin.register(SideBar, site=custom_site) +class SideBarAdmin(admin.ModelAdmin): + list_display = ('title', 'status', 'display_type', 'created_time',) + list_filter = ('status', 'display_type',) + search_fields = ('title',) diff --git a/typeidea/config/forms.py b/typeidea/config/forms.py new file mode 100644 index 0000000..70ba725 --- /dev/null +++ b/typeidea/config/forms.py @@ -0,0 +1,16 @@ +# coding:utf-8 +from __future__ import unicode_literals + +from django import forms + +from .models import Link, SideBar + + +class LinkForm(forms.ModelForm): + class Meta: + model = Link + + +class SideBatForm(forms.ModelForm): + class Meta: + model = SideBar diff --git a/typeidea/config/models.py b/typeidea/config/models.py index e1ea41d..f09491b 100644 --- a/typeidea/config/models.py +++ b/typeidea/config/models.py @@ -36,6 +36,7 @@ class SideBar(models.Model): (4, '最近评论'), ) title = models.CharField(max_length=50, verbose_name="标题") + status = models.PositiveIntegerField(default=1, choices=STATUS_ITEMS, verbose_name="状态") display_type = models.PositiveIntegerField(default=1, choices=SIDE_TYPE, verbose_name="展示类型") content = models.CharField(max_length=500, blank=True, verbose_name="内容",