标签:imp 用户登录 tar run man django apt col []
使用用django提供的管理后台,对model表数据操作
1、 建立model
2、在admin.py文件中引入modle,然后注册
3、创建超级用户登录就可以向数据库中增删改查数据了
from django.contrib import admin
from app_crm import models
# 在这个文件中注册models中的表,就可以在admin网页中手动添加数据
# Register your models here.
admin.site.register(models.Campuses)
admin.site.register(models.ClassList)
admin.site.register(models.Customer)
admin.site.register(models.Department)
1、建立model,然后在顶部设置__all__ = [] 变量,将需要添加的model表加入到列表中
__all__ = ["Category", "Course", "CourseDetail", "Teacher", "DegreeCourse", "CourseChapter",
"CourseSection", "PricePolicy", "OftenAskedQuestion", "Comment", "Account", "CourseOutline"]
2、在admin.py文件中注册,通过反射的方式
from django.contrib import admin
from api_luffy import models
# Register your models here.
for table in models.__all__:
admin.site.register(getattr(models, table))
3、创建超级用户
from django.contrib import admin
from app01 import models
# Register your models here.
# 将字段的字段名和值展示出来,格式必须是“字段名Admin”
class PermissionAdmin(admin.ModelAdmin):
list_display = [‘name‘, ‘url‘]
list_editable = [‘url‘]
# 经测试多对多的字段没法展示
class UserAdmin(admin.ModelAdmin):
list_display = [‘username‘, ‘password‘, ‘email‘]
admin.site.register(models.User, UserAdmin)
admin.site.register(models.Role)
admin.site.register(models.Permission, PermissionAdmin)
详细见菜鸟:http://www.runoob.com/django/django-admin-manage-tool.html
标签:imp 用户登录 tar run man django apt col []
原文地址:https://www.cnblogs.com/sunxiuwen/p/10055978.html