· 9 years ago · Dec 01, 2016, 05:36 AM
1#models.py
2from django.db import models
3from django.utils import timezone
4
5
6class Post(models.Model):
7 author = models.ForeignKey('auth.User')
8 title = models.CharField(max_length=200)
9 text = models.TextField()
10 created_date = models.DateTimeField(default=timezone.now)
11 published_date = models.DateTimeField(blank=True, null=True)
12
13 def publish(self):
14 self.published_date = timezone.now()
15 self.save()
16
17 def __str__(self):
18 return self.title
19
20#settings.py
21"""
22Django settings for mysite project.
23
24Generated by 'django-admin startproject' using Django 1.10.3.
25
26For more information on this file, see
27https://docs.djangoproject.com/en/1.10/topics/settings/
28
29For the full list of settings and their values, see
30https://docs.djangoproject.com/en/1.10/ref/settings/
31"""
32
33import os
34
35# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
36BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37
38
39# Quick-start development settings - unsuitable for production
40# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
41
42# SECURITY WARNING: keep the secret key used in production secret!
43SECRET_KEY = 'yl6h8q0l12uh+!c4uys#-6d)6k$#t*x@64=$42zh7ajxw+qir5'
44
45# SECURITY WARNING: don't run with debug turned on in production!
46DEBUG = True
47
48ALLOWED_HOSTS = []
49
50
51# Application definition
52
53INSTALLED_APPS = [
54 'django.contrib.sites',
55 'django.contrib.admin',
56 'django.contrib.auth',
57 'django.contrib.contenttypes',
58 'django.contrib.sessions',
59 'django.contrib.messages',
60 'django.contrib.staticfiles',
61 'blog',
62]
63
64MIDDLEWARE = [
65 'django.middleware.security.SecurityMiddleware',
66 'django.contrib.sessions.middleware.SessionMiddleware',
67 'django.middleware.common.CommonMiddleware',
68 'django.middleware.csrf.CsrfViewMiddleware',
69 'django.contrib.auth.middleware.AuthenticationMiddleware',
70 'django.contrib.messages.middleware.MessageMiddleware',
71 'django.middleware.clickjacking.XFrameOptionsMiddleware',
72]
73
74ROOT_URLCONF = 'mysite.urls'
75
76TEMPLATES = [
77 {
78 'BACKEND': 'django.template.backends.django.DjangoTemplates',
79 'DIRS': [],
80 'APP_DIRS': True,
81 'OPTIONS': {
82 'context_processors': [
83 'django.template.context_processors.debug',
84 'django.template.context_processors.request',
85 'django.contrib.auth.context_processors.auth',
86 'django.contrib.messages.context_processors.messages',
87 ],
88 },
89 },
90]
91
92WSGI_APPLICATION = 'mysite.wsgi.application'
93
94
95# Database
96# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
97
98DATABASES = {
99 'default': {
100 'ENGINE': 'django.db.backends.sqlite3',
101 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
102 }
103}
104
105
106# Password validation
107# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
108
109AUTH_PASSWORD_VALIDATORS = [
110 {
111 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
112 },
113 {
114 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
115 },
116 {
117 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
118 },
119 {
120 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
121 },
122]
123
124
125# Internationalization
126# https://docs.djangoproject.com/en/1.10/topics/i18n/
127
128LANGUAGE_CODE = 'ru-RU'
129
130TIME_ZONE = 'Asia/Vladivostok'
131
132USE_I18N = True
133
134USE_L10N = True
135
136USE_TZ = True
137
138SITE_ID = 1
139
140
141# Static files (CSS, JavaScript, Images)
142# https://docs.djangoproject.com/en/1.10/howto/static-files/
143
144STATIC_URL = '/static/'
145STATIC_ROOT = os.path.join(BASE_DIR, 'static')