django-admin.py startproject simplecmdb
python manage.py startapp hostinfo
3.停用老项目,启用新项目
python manage.py runserver 0.0.0.0:8000
4.hostinfo下models.py定义表models.py,其实就是定义类
class Host(models.Model): hostname = models.CharField(max_length=50) ip = models.IPAddressField() vendor = models.CharField(max_length=50) product = models.CharField(max_length=50) sn = models.CharField(max_length=50) #位数一定要足够,否则使用urllib2模块会报500 cpu_model = models.CharField(max_length=50) cpu_num = models.IntegerField() memory = models.CharField(max_length=50) osver = models.CharField(max_length=50)
5.先检查是否语法错误,查看要执行的脚本语句;同步数据库
python manage.py validate
python manage.py sqlall hostinfo
python manage.py syncdb
6.应用下admin.py注册配置,定义显示字段,并且注册该类
from hostinfo.models import Host
class HostAdmin(admin.ModelAdmin):
list_display = [
"hostname",
"ip",
"cpu_model",
"cpu_num",
"memory",
"vendor",
"product",
"osver",
"sn"
]
admin.site.register(Host,HostAdmin)
7.web查看
原文地址:http://blog.51cto.com/huangzp/2089705