Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成评论和其他设置的admin、form模块 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion typeidea/comment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions typeidea/comment/forms.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion typeidea/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8 fix



@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',)
16 changes: 16 additions & 0 deletions typeidea/config/forms.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions typeidea/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="内容",
Expand Down