Before we had created the virtual environment and started a project.
Now that we're going to add some functional code, Django encourages us to put the code we've written into the app, and each app implements a feature.
Now create a new blog app
1, in the virtual environment into the root directory, run Python manage.py startapp blog. Built a blog app called Apps.
2, in setting.py ' Tell ' Django there is an app like this.
Well, we already have the blog this app, is to achieve blog posts, blog posts should contain the title, text, author, publication time and other data. A more modern blog post also wants it to be categorized, tagged, commented, and so on. To better store this data, we need to properly organize the table structure of the database.
For example, the database table label and classification, there is a lot of duplication of data, this we have to create a new table for them, and then associate them together.
Need to note:
1, all need to inherit from models. Model class
2, the relationship between the tables, ForeignKey represents a one-to-many relationship, such as an article has only one classification, but a classification can correspond to many articles.
Manytomanyfield An article can have a number of tags, a label can have many articles.
Writing the application of the models.py in principle has been said, no longer repeat.
The database model of the creation blog of Django Building blog system