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="内容",