Skip to content

Commit 5bdf6a0

Browse files
committed
feat: Set up database and create models
resolved #8 - 데이터베이스 설치 - 모델 생성 및 활성화 - 모델 메서드 추가 및 api 사용
1 parent b95547c commit 5bdf6a0

16 files changed

+60
-4
lines changed
146 Bytes
Binary file not shown.
Binary file not shown.
974 Bytes
Binary file not shown.
547 Bytes
Binary file not shown.

mysite/mysite/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34+
'polls.apps.PollsConfig',
3435
'django.contrib.admin',
3536
'django.contrib.auth',
3637
'django.contrib.contenttypes',
@@ -105,13 +106,13 @@
105106

106107
LANGUAGE_CODE = 'en-us'
107108

108-
TIME_ZONE = 'UTC'
109+
TIME_ZONE = 'Asia/Seoul'
109110

110111
USE_I18N = True
111112

112113
USE_L10N = True
113114

114-
USE_TZ = True
115+
USE_TZ = False
115116

116117

117118
# Static files (CSS, JavaScript, Images)

mysite/mysite/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import path
17+
from django.urls import path, include
1818

1919
urlpatterns = [
20+
# route : url 패턴
21+
path('polls/', include('polls.urls')), # 다른 url 패턴을 포함할 때 include 함수 사용
2022
path('admin/', admin.site.urls),
2123
]
0 Bytes
Binary file not shown.
186 Bytes
Binary file not shown.
420 Bytes
Binary file not shown.
1.24 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 3.2.6 on 2021-08-24 17:48
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.BigAutoField(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.BigAutoField(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+
]
Binary file not shown.
Binary file not shown.

mysite/polls/models.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
import datetime
2+
13
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)
222

3-
# Create your models here.
23+
def __str__(self):
24+
return self.choice_text

0 commit comments

Comments
 (0)