标签:自动 isp setting actions desc use top rtp 启用
python manage.py createsuperuser
然后按提示填写用户名、邮箱、密码
from django.contrib import admin
from models import *
admin.site.register(HeroInfo)
class HeroAdmin(admin.ModelAdmin):
...
admin.site.register(HeroInfo,HeroAdmin)
@admin.register(HeroInfo)
class HeroAdmin(admin.ModelAdmin):
class HeroAdmin(admin.ModelAdmin):
actions_on_top = True
actions_on_bottom = True
在models.py文件中
from django.db import models
from tinymce.models import HTMLField
from django.utils.html import format_html
class HeroInfo(models.Model):
hname = models.CharField(max_length=10)
hcontent = HTMLField()
isDelete = models.BooleanField()
def hContent(self):
return format_html(self.hcontent)
在admin.py文件中
class HeroAdmin(admin.ModelAdmin):
list_display = [‘hname‘, ‘hContent‘]
在models.py中HeroInfo类的代码改为如下:
def hContent(self):
return format_html(self.hcontent)
hContent.admin_order_field = ‘hname‘
在models.py中为HeroInfo类增加方法hName:
def hName(self):
return self.hname
hName.short_description = ‘姓名‘
hContent.short_description = ‘内容‘
在admin.py页中注册
class HeroAdmin(admin.ModelAdmin):
list_display = [‘hName‘, ‘hContent‘]
class HeroAdmin(admin.ModelAdmin):
...
list_filter = [‘hname‘, ‘hcontent‘]
class HeroAdmin(admin.ModelAdmin):
...
list_per_page = 10
class HeroAdmin(admin.ModelAdmin):
...
search_fields = [‘hname‘]
class HeroAdmin(admin.ModelAdmin):
...
fields = [(‘hname‘, ‘hcontent‘)]
class HeroAdmin(admin.ModelAdmin):
...
fieldsets = (
(‘base‘, {‘fields‘: (‘hname‘)}),
(‘other‘, {‘fields‘: (‘hcontent‘)})
)
class HeroInline(admin.TabularInline):
model = HeroInfo
class BookAdmin(admin.ModelAdmin):
inlines = [
HeroInline,
]
‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)],
标签:自动 isp setting actions desc use top rtp 启用
原文地址:http://www.cnblogs.com/huwei934/p/6978720.html