๋ฐ์ํ
ํฐ๋ฏธ๋(๋ก์ปฌ)ํ๊ฒฝ.
- ๋ชจ๋ Model ๊ฐ์ฒด๋ blog/models.py ํ์ผ์ ์ ์ธํ์ฌ ๋ชจ๋ธ์ ์์ฑํ๋ค.
models : Post๊ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋จ์ ์ฅ๊ณ ๊ฐ ์ธ์งํ ์ ์๋ค.
models.ForeignKey : ๋ค๋ฅธ ๋ชจ๋ธ์ ๋ํ ๋งํฌ ์๋ฏธ
models.charField : ๊ธ์ ์๊ฐ ์ ํ๋ ํ ์คํธ
models.TextField : ๊ธ์ ์์ ์ ํ์ด ์๋ ๊ธด ํ ์คํธ
models.DateTimeField : ๋ ์ง์ ์๊ฐ
def publish(self): publish ๋ฉ์๋๋ก
(base) dojiyeong@dojiyeong-ui-MacBookPro ~ % cd /Users/dojiyeong/venv/myvenv/source/firstsite
(base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % source /Users/dojiyeong/venv/myvenv/bin/activate
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % cd firstsite
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % cd
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro ~ % cd /Users/dojiyeong/venv/myvenv/source/firstsite
#(๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์๋ก ๋ง๋ ๋ชจ๋ธ Post ๋ชจ๋ธ ์ถ๊ฐ/ ์๋ ค์ฃผ๊ธฐ)
myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % python ./manage.py makemigrations blog
Migrations for 'blog':
blog/migrations/0001_initial.py
- Create model Post
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % python ./manage.py migrate blog
Operations to perform:
Apply all migrations: blog
Running migrations:
Applying blog.0001_initial... OK
# ์ํผ ์ ์ (๋) ๋ง๋ค๊ธฐ
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % python ./manage.py createsuperuser
Username (leave blank to use 'dojiyeong'): ใ
ใ
ใ
ใ
ใ
ใ
Email address: ใ
ใ
ใ
ใ
ใ
ใ
Password:
Password (again):
Superuser created successfully.
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % python manage.py runserver
Performing system checks...
#์ฅ๊ณ ์ธํฐ๋ํฐ๋ธ ์ฝ์
(myvenv) (base) dojiyeong@dojiyeong-ui-MacBookPro firstsite % python ./manage.py shell
Python 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post
>>> Post.objects.all()
<QuerySet []>
>>> from django.contrib.auth.models import User
>>> User.objects.all()
<QuerySet [<User: ehwl0129>]>
>>> me = User.objects.get(username='ehwl0129')
>>> Post.objects.create(author=me, title='ํฐ๋ฏธ๋์์ ์
๋ ฅ',text='ํ
์คํธ์
๋๋ค.')
<Post: ํฐ๋ฏธ๋์์ ์
๋ ฅ>
>>> Post.objects.all()
<QuerySet [<Post: ์ฒด๋ฆฌ>, <Post: ํฐ๋ฏธ๋์์ ์
๋ ฅ>]>
>>> Post.objects.create(author=me, title='test',text='ํ
์คํธ์
๋๋ค.')
<Post: test>
>>> Post.objects.all()
<QuerySet [<Post: ์ฒด๋ฆฌ>, <Post: ํฐ๋ฏธ๋์์ ์
๋ ฅ>, <Post: test>]>
์์ ๊ฐ์ ๊ณผ์ ์ ๋๊ฐ์ด
Pythonanywhere ์ฝ์์์ ์งํํ๋ฉด (git pull ์งํ!)
Pyhonanywhrere/admin ์์๋ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๋์ํ๋ค.
๋ฐ์ํ
'Django_Web' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Django] ์ ๋ก๋ํ ํ์ผ ๋ด๊ฐ ์ํ๋ ๋๋ก ์ฒ๋ฆฌํ๊ธฐ (0) | 2021.07.19 |
---|---|
[Django][FusionCharts] ์ฌ์ฉ๋ฐฉ๋ฒ & ์ฅ๊ณ ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ (0) | 2021.06.13 |
[Django] ํ์ผ ์ ๋ก๋ ๊ธ๋ก๋ฒ ์๋น์ค ๊ตฌํํ๊ธฐ (0) | 2021.06.09 |
Django - PythonAnywhere ๊ธ๋ก๋ฒ ์๋น์ค ์์ํ๊ธฐ (0) | 2021.06.02 |
pyrhonanywhere.com ์๋น์ค ์์ํ๊ธฐ (0) | 2021.03.30 |
๋๊ธ