23.03.2017 Views

wilamowski-b-m-irwin-j-d-industrial-communication-systems-2011

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

63-4 Industrial Communication Systems<br />

FIGURE 63.5<br />

Web site of the server.<br />

63.3.3 Setup Database<br />

The database information is configured in the file setting.py. There are very detailed instructions<br />

about each parameter in the file. In this example, let us fulfill the basic settings as follows:<br />

DATABASE _ ENGINE = 'sqlite3'<br />

DATABASE _ NAME = 'C:/paper _ system/sqlite3.db'<br />

The first parameter indicates that SQLite database (included in the standard Python library) stores<br />

all the information in a single file on the computer, while the second parameter specifies the location of<br />

SQLite database file.<br />

After the configuration of file setting.py, enter the command manage.py syncdb to create the<br />

database and register a super-user for the auth system. See Figure 63.6.<br />

63.3.4 Create Model<br />

So far, a project has been set up. In the following, the document database is going to be built based on<br />

the project. Notice that Django supports multiple applications, which means a project can have multiple<br />

applications and an application can be in multiple projects.<br />

By entering the command manage.py startapp documents, a directory named documents<br />

is created with four files inside: __ init __ .py, models.py, tests.py, and views.py.<br />

The file models.py is used to build the model. In this example, a Document model will be described<br />

in documents/models.py file as<br />

FIGURE 63.6<br />

Database setup.<br />

© <strong>2011</strong> by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!