From 79dc2c3982e0f508a18f1399c1a73b55ff58b14f Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Mon, 19 Oct 2020 15:41:33 +1100 Subject: [PATCH] Finished 3. Django admin --- django-girls.md | 39 ++++++++++++++++++++++++++++++++++++++- src/blog/admin.py | 3 ++- src/db.sqlite3 | Bin 139264 -> 139264 bytes 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/django-girls.md b/django-girls.md index 5b67ce0..81eb2e5 100644 --- a/django-girls.md +++ b/django-girls.md @@ -178,4 +178,41 @@ After creating new model, we need to add it into database: 1. Let Django know there is change: `python manage.py makemigrations blog` 1. So, Django will prepare a migration file -2. After prepared migration file `blog/migrations/0001_initial.py`, apply it to database: `python manage.py migrate blog` \ No newline at end of file +2. After prepared migration file `blog/migrations/0001_initial.py`, apply it to database: `python manage.py migrate blog` + +## 3. Django admin + +To adding/editing posts, need use Django admin + +### 3.1 Add Post models into admin site + +Edit `blog/admin.py` + +```python +from django.contrib import admin +from .models import Post + +admin.site.register(Post) +``` + +### 3.2 Add superuser to get access + +``` +python manage.py createsuperuser +``` + +### 3.3 Add/Edit post in admin site + +Start webserver `python manage.py runserver` then go to http://127.0.0.1/admin + +In the post, we can find it has multiple attributes/members including: +* `author` +* `Title` +* `Text` +* `Created date` +* `Published date` + +They are all forms that we created in Post model + +## 4. Deploy (Omit) + diff --git a/src/blog/admin.py b/src/blog/admin.py index 8c38f3f..112f607 100644 --- a/src/blog/admin.py +++ b/src/blog/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin +from .models import Post -# Register your models here. +admin.site.register(Post) \ No newline at end of file diff --git a/src/db.sqlite3 b/src/db.sqlite3 index 1ce9a2cad7d18e51c47d22fa39655d20bd894f88..110a913b917bfc57245ab2dd6d2c4f108435760d 100644 GIT binary patch delta 1075 zcmah|O=}xR7~av^k=Ly}P20qWq)0dlq%@LuXFp^M0+qZ*s_eBCeb}-?Snq0A(rQ1Y z)t4QDqx4t^Ej<)^?zK?Ihd_Es|A8qzl#o+yrj*h{@S%ZbWVa!83mx7W7~Xjv-uHRl zx%Xu1-jk`%FM;S6mzO|vfBT#8yFs{3z$3T~zlVMJ8T=Z4yFbdoi|>)>eq5`7N9DgmqeqcylUx(Y(X=))8>8=9x6RLE0Jt&U{BsUTj6B1WKTI@;LHqng4O zD!XbrY889#vemjxjhEBQ%#} z1srjPMhPL&Qhe8GDJ(ue)`yDiS$e$Y+GhYL$*^&b7iea28aD#qF#(Sc&Tsz;r>DqS z>Vzb806g-Yb71BvG4phPbU3qj{|cCtKCPsDcHp{$I_G%iusKxPJU6t>wxiLGp{ZQI z6W4RY^_J-82d&i2v@RPN%TCDtM$^mJB+Jpd+#tQ(hH!!y9<%wCp zzzY*31p*{VQK6I60|Nd4A7I>lxW@!2A_c?e0R_&OpGdNaI8SpN%`;`)??%QGe(QEH za08q`J^~c=ZwMP_@YEvi4al82MbmU`E*ZIV_wMcBxQ5GbJ;!ashwxG85FCf`kHGim zxT2rowGYVDU%dY%+87PsV*))1m2d)9@oW bx_|d@rf4C_Cr+(+i6z6Vzrpe69n19!BlRlH delta 160 zcmZoTz|nAkV}dlJ+(a2?M!Ag%OXP*v_{$jhU-Dn!-_2jf-_1XZzhYx!0{`SPeGMg! z#L|+C_|oFkA_fKqVIW2Z;;hWZjMG0lF$#;Z3o|q8a-?J>=B4MyC#K|P=Edjar*D3# wFKw`y<-s5MMF#{n9bggI%(CH+Jdp7KCOByV%W{?rj0%fcHYjXnY52nr0BTh;EC2ui