Target: create objects that store all posts in the blog.
### 2.1 Objects
In OOP, object containing member data and member function. We try to model the blog's objects as well.
Q:
* How will we model blog posts?
* What is a blog post?
* What properties should it have?
A:
* Blog posts need
* text with content and title
* author
* date of created/published
Object's data can be shown as below:
```
Post
-------
title
text
author
created_date
published_date
```
Blog object's method:
*`publish`
### 2.2 Django model
A model in Django is a special kind of obj, saved in `database`. Analogy: A model in database is like a spreadsheet with columns (fields) and rows (data).
#### 2.2.1 Creating and app
For organization, we create a separate app inside the web project, which contains logic and model.
```
$ python manage.py startapp blog
```
It created a dir called `/blog` that containing scripts:
```
djangogirls
├── blog
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
|...
```
After creating app, `mysite/settings.py` should be changed to let Django notice the app.
```python
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# first party
'blog.apps.BlogConfig',
]
```
*`blog.apps.BlogConfig` is the class that in `blog/apps.py` script
#### 2.2.2 Creating a blog post model
For each app, there is a `models.py` that contains models (obj), modify it to contain post obj