美文网首页
2(modules, admin)

2(modules, admin)

作者: EudeMo | 来源:发表于2015-11-08 22:51 被阅读0次

    创建modules.py,修改admin.py

    1. 修改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
    
    1. 修改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)
    
    1. 修改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',
    )
    
    1. 访问127.0.0.1:8000/admin

    相关文章

      网友评论

          本文标题:2(modules, admin)

          本文链接:https://www.haomeiwen.com/subject/adachttx.html