Skip to content

Commit 573b988

Browse files
committed
Iniciando projeto. Código desenvolvido até a parte 3 do tutorial
0 parents  commit 573b988

19 files changed

+466
-0
lines changed

.gitignore

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/django
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=django
3+
4+
### Django ###
5+
*.log
6+
*.pot
7+
*.pyc
8+
__pycache__/
9+
local_settings.py
10+
db.sqlite3
11+
db.sqlite3-journal
12+
media
13+
14+
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
15+
# in your Git repository. Update and uncomment the following line accordingly.
16+
# <django-project-name>/staticfiles/
17+
18+
### Django.Python Stack ###
19+
# Byte-compiled / optimized / DLL files
20+
*.py[cod]
21+
*$py.class
22+
23+
# C extensions
24+
*.so
25+
26+
# Distribution / packaging
27+
.Python
28+
build/
29+
develop-eggs/
30+
dist/
31+
downloads/
32+
eggs/
33+
.eggs/
34+
lib/
35+
lib64/
36+
parts/
37+
sdist/
38+
var/
39+
wheels/
40+
pip-wheel-metadata/
41+
share/python-wheels/
42+
*.egg-info/
43+
.installed.cfg
44+
*.egg
45+
MANIFEST
46+
47+
# PyInstaller
48+
# Usually these files are written by a python script from a template
49+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
50+
*.manifest
51+
*.spec
52+
53+
# Installer logs
54+
pip-log.txt
55+
pip-delete-this-directory.txt
56+
57+
# Unit test / coverage reports
58+
htmlcov/
59+
.tox/
60+
.nox/
61+
.coverage
62+
.coverage.*
63+
.cache
64+
nosetests.xml
65+
coverage.xml
66+
*.cover
67+
*.py,cover
68+
.hypothesis/
69+
.pytest_cache/
70+
71+
# Translations
72+
*.mo
73+
74+
# Django stuff:
75+
76+
# Flask stuff:
77+
instance/
78+
.webassets-cache
79+
80+
# Scrapy stuff:
81+
.scrapy
82+
83+
# Sphinx documentation
84+
docs/_build/
85+
86+
# PyBuilder
87+
target/
88+
89+
# Jupyter Notebook
90+
.ipynb_checkpoints
91+
92+
# IPython
93+
profile_default/
94+
ipython_config.py
95+
96+
# pyenv
97+
.python-version
98+
99+
# pipenv
100+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
101+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
102+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
103+
# install all needed dependencies.
104+
#Pipfile.lock
105+
106+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
107+
__pypackages__/
108+
109+
# Celery stuff
110+
celerybeat-schedule
111+
celerybeat.pid
112+
113+
# SageMath parsed files
114+
*.sage.py
115+
116+
# Environments
117+
.env
118+
.venv
119+
env/
120+
venv/
121+
ENV/
122+
env.bak/
123+
venv.bak/
124+
125+
# Spyder project settings
126+
.spyderproject
127+
.spyproject
128+
129+
# Rope project settings
130+
.ropeproject
131+
132+
# mkdocs documentation
133+
/site
134+
135+
# mypy
136+
.mypy_cache/
137+
.dmypy.json
138+
dmypy.json
139+
140+
# Pyre type checker
141+
.pyre/
142+
143+
# pytype static type analyzer
144+
.pytype/
145+
146+
# End of https://www.toptal.com/developers/gitignore/api/django

manage.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
9+
try:
10+
from django.core.management import execute_from_command_line
11+
except ImportError as exc:
12+
raise ImportError(
13+
"Couldn't import Django. Are you sure it's installed and "
14+
"available on your PYTHONPATH environment variable? Did you "
15+
"forget to activate a virtual environment?"
16+
) from exc
17+
execute_from_command_line(sys.argv)
18+
19+
20+
if __name__ == '__main__':
21+
main()

mysite/__init__.py

Whitespace-only changes.

mysite/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for mysite project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
15+
16+
application = get_asgi_application()

mysite/settings.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""
2+
Django settings for mysite project.
3+
4+
Generated by 'django-admin startproject' using Django 3.0.8.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/3.0/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'ea0ds&xbu_!a7svt@d-di2kcxxz!i_yot!iu2-d^#a%dm(kxyv'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'polls.apps.PollsConfig',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'mysite.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'mysite.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81+
}
82+
}
83+
84+
# Password validation
85+
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
86+
87+
AUTH_PASSWORD_VALIDATORS = [
88+
89+
]
90+
91+
92+
# Internationalization
93+
# https://docs.djangoproject.com/en/3.0/topics/i18n/
94+
95+
LANGUAGE_CODE = 'pt-BR'
96+
97+
TIME_ZONE = 'America/Sao_Paulo'
98+
99+
USE_I18N = True
100+
101+
USE_L10N = True
102+
103+
USE_TZ = True
104+
105+
106+
# Static files (CSS', 'JavaScript', 'Images)
107+
# https://docs.djangoproject.com/en/3.0/howto/static-files/
108+
109+
STATIC_URL = '/static/'

mysite/urls.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import include, path
3+
4+
urlpatterns = [
5+
path('polls/', include('polls.urls')),
6+
path('admin/', admin.site.urls),
7+
]

mysite/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for mysite project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
15+
16+
application = get_wsgi_application()

polls/__init__.py

Whitespace-only changes.

polls/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from .models import Question, Choice
4+
5+
admin.site.register(Question)
6+
admin.site.register(Choice)

polls/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class PollsConfig(AppConfig):
5+
name = 'polls'

polls/migrations/0001_initial.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 3.0.8 on 2020-07-09 00:37
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Question',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('question_text', models.CharField(max_length=200)),
20+
('pub_date', models.DateTimeField(verbose_name='date published')),
21+
],
22+
),
23+
migrations.CreateModel(
24+
name='Choice',
25+
fields=[
26+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27+
('choice_text', models.CharField(max_length=200)),
28+
('votes', models.IntegerField(default=0)),
29+
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question')),
30+
],
31+
),
32+
]

polls/migrations/__init__.py

Whitespace-only changes.

polls/models.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import datetime
2+
3+
from django.db import models
4+
from django.utils import timezone
5+
6+
7+
class Question(models.Model):
8+
question_text = models.CharField(max_length=200)
9+
pub_date = models.DateTimeField('date published')
10+
11+
def __str__(self):
12+
return self.question_text
13+
14+
def was_published_recently(self):
15+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
16+
17+
18+
class Choice(models.Model):
19+
question = models.ForeignKey(Question, on_delete=models.CASCADE)
20+
choice_text = models.CharField(max_length=200)
21+
votes = models.IntegerField(default=0)
22+
23+
def __str__(self):
24+
return self.choice_text

polls/templates/index.html

Whitespace-only changes.

0 commit comments

Comments
 (0)