python manage.py createsuperuser
from django.db import models
# Create your models here.
class Player(models.Model):
name = models.CharField(
max_length=30,
verbose_name="游戏名"
)
desc = models.CharField(
max_length=251,
verbose_name="简介"
)
rate = models.FloatField(
verbose_name="评分"
)
def __str__(self):
return self.name
class Humen(models.Model):
name = models.CharField(
max_length=30,
verbose_name="角色名字"
)
player = models.ForeignKey(
Player,
verbose_name="所属游戏"
)
# 注册你的model
# admin.site.register(类名)
admin.site.register(Player, PlayerAdmin)
admin.site.register(Humen)
from django.contrib import admin
from .models import Player, Humen
# Register your models here.
class HumenInfo(admin.TabularInline):
# 指定model
model = Humen
# 指定增加的条数
extra = 2
class PlayerAdmin(admin.ModelAdmin):
def get_rate_level(self):
if self.rate > 9:
return "玩"
else:
return "不玩"
get_rate_level.short_description = "评价"
# 显示
list_display = ['name', 'rate', 'desc', get_rate_level]
# 过滤器
list_filter = ['rate', 'desc']
# 搜索
search_fields = ['name']
# 分页
list_per_page = 1
# 信息分组
fieldsets = [
("基本信息", {"fields": ("name", "desc")}),
("附加信息", {"fields": ("rate",)})
]
inlines = [HumenInfo]
# 注册你的model
admin.site.register(Player, PlayerAdmin)
admin.site.register(Humen)
1.首先把admin的路径拿到
在虚拟环境目录下的lib目录下下下下的admin里
/home/ubuntu/gz1803/py3_gz1803/lib/python3.6/site-packages/django/contrib/admin/templates/admin
复写里面的login.html文件,在templates里创建admin目录,创建login.html和index.html文件
复制我们路径下的代码,copy到创建的html中,把base_site.html中的一段代码拷贝出来
{% block branding %}
{{ site_header|default:_('Django administration') }}
{% endblock %}
复制到login.html和index.py中
login.html修改的首页的表头 在index.html中修改的
{% block branding %}
贼鸡儿困
{% endblock %}
{% block branding %}
无聊
{% endblock %}
在admin.py 中继承AdminSite
class MyAdmin(admin.AdminSite):
# 管理网页的页头部的标题
site_header = "qwer"
# 浏览窗口显示的页面名称
site_title = "asdf"
# 查看站点的跳转,
site_url = "http://www.baidu.com"
site = MyAdmin()
site.register(Player, PlayerAdmin)
最后在工程的urls.pyz中修改admin的跳转
from dj06app.admin import site
urlpatterns = [
# url(r'^admin/', admin.site.urls),
url(r'^admin/', site.urls),