Web2py -------------- example of using web2py to write django, web2pydjango

Source: Internet
Author: User
Tags web2py

Web2py -------------- example of using web2py to write django, web2pydjango

Model Creation

Under models and where polls. py

The file content is as follows:

1 #-*-coding: UTF-8-*-2 pollsdb = DAL (uri = 'sqlite: // polls. db') 3 4 pollsdb. define_table ('Question ', 5 Field ('Question _ text', 'string', length = 200), 6 Field ('pub _ date', 'datetime '), 7 format = '% (question_text) s') 8 9 pollsdb. define_table ('choice ', 10 Field ('Question', 'reference question ', requires = IS_IN_DB (pollsdb, 'Question. id', pollsdb. question. _ format), 11 Field ('choice _ text', 'string', length = 200), 12 Field ('votes ', 'integer', default = 0 ), 13 format = '% (choice_text) s ')Polls. py

Detailed sales details I wrote above to facilitate Paste

To explain, pollsdb is a database file. The official DAL is an independent plug-in that supports many databases. Here sqlite is used.

Create two data tables, Question and Choice.

The Choice table has the question field as the foreign key.

We can log on to the background management to see

Enter http: // 127.0.0.1/polls/appadmin/

Enter the management password

We can see the two tables we have created and the system permission table, but it does not matter for this application currently.

We can add new records for the Question table.

Click the new record button

We can see that the datetime data is web2py, which provides a plug-in for us to select the time.

Enter and click Submit

Click the table name on the management interface to view the list.

It is indeed a simple management interface, but developers do not care about these details

Let's take a look at the Choice add page in the same way.

It should be a perfect presentation. The system has made a foreign key Association.

The model creation here is over.

Exercises after class

Try to use different databases

The system provides us with many verification tools. You can try it. Here we only use IS_IN_DB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.