创建modules.py,修改admin.py
- 修改modules.py
# Create your models here.
from django.db import models
class AppName(models.Model):
title = models.CharField(max_length=120,blank=False,null=False)
description = models.TextField()
narrative = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
def __unicode__(self):#python3.3以上这里要用__str__,用来返回需要显示的项目,
return str(self.title) #如果还要显示别的,参考amdin.py中的list_display
- 修改admin.py
from django.contrib import admin
# Register your models here.
from .models import AppName
class AppNameAdmin(admin.ModelAdmin):
list_display = ["__unicode__","description","narrative","timestamp"]
class meta:
model = APPName
admin.site.register(AppName, AppNameAdmin)
- 修改settings.py
在installed_app里边添加projectname
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ProjectName',
)
- 访问127.0.0.1:8000/admin