Django Models 参数

我创建model必加的字段


class Category(models.Model):

    pub_date = models.DateTimeField('发布日期',auto_now_add=True)
    update_date = models.DateTimeField('更新日期',auto_now=True)
    sort = models.IntegerField("序号",default=99,help_text="序号越小越靠前")
    def __unicode__(self):
        return self.title
    def __str__(self):
        return self.title    
    class Meta:
        verbose_name = '目录'
        verbose_name_plural = '0-目录'
        ordering = ['sort']  # 按照哪个栏目排序
        get_latest_by = 'pub_date'

创建了新的 Django Project 后需要设置的

  1. 创建 Env
    virtualenv venv
  2. 生成 git 目录
    git init
  3. 加入gitignore
    # Byte-compiled / optimized / DLL files
    __pycache__/
    *.py[cod]
    
    # C extensions
    *.so
    
    # Distribution / packaging
    bin/
    build/
    develop-eggs/
    dist/
    eggs/
    lib/
    lib64/
    parts/
    sdist/
    var/
    venv/
    collectstatic/
    *.egg-info/
    .installed.cfg
    *.egg
    
    # Installer logs
    pip-log.txt
    pip-delete-this-directory.txt
    
    # Unit test / coverage reports
    .tox/
    .coverage
    .cache
    nosetests.xml
    coverage.xml
    
    # Translations
    *.mo
    
    # Mr Developer
    .mr.developer.cfg
    .project
    .pydevproject
    
    # Rope
    .ropeproject
    
    # Django stuff:
    *.log
    *.pot
    
    # Sphinx documentation
    docs/_build/
    
    # editor
    .vscode
    
    # database
    db.sqlite3
  4. 修改中文
    LANGUAGE_CODE = 'zh-hans'
    
    TIME_ZONE = 'Asia/Shanghai'
  5. 设置静态文件目录
    STATIC_ROOT = 'collectstatic'
  6. Database
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql', #数据库引擎
            'NAME': 'user_im',                       #数据库名
            'USER': 'root',                       #用户名
            'PASSWORD': '',                   #密码
            'HOST': '',                           #数据库主机,默认为localhost
            'PORT': '',                           #数据库端口,MySQL默认为3306
            'OPTIONS': {
                'autocommit': True,
            },
        }
    }