django建站过程添加导入导出功能
from django.contrib import admin
from .models import Topic, Webpage, AccessRecord
class AccessRecordAdmin(admin.ModelAdmin):
list_display = ('id', 'topic', 'webpage', 'date_accessed')
list_filter = ('date_accessed',)
search_fields = ('topic',)
admin.site.register(AccessRecord, AccessRecordAdmin)
class WebpageAdmin(admin.ModelAdmin):
list_display = ('id', 'topic', 'url', 'date_created')
list_filter = ('date_created', 'topic',)
search_fields = ('topic', 'url')
admin.site.register(Webpage, WebpageAdmin)
class TopicAdmin(admin.ModelAdmin):
list_display = ('id', 'top_level_topic', 'name')
list_filter = ('top_level_topic',)
search_fields = ('name',)
admin.site.register(Topic, TopicAdmin)
这个代码实例展示了如何在Django的admin后台注册模型,并定制显示字段、过滤器和搜索字段,以便更好地管理数据。
评论已关闭