[Answer]-Web2py or Django: code example for web site that looks similar to the admin page

1đź‘Ť

web2py includes an “admin” app, which is a web-based IDE for creating, editing, and managing apps. It is a separate app with a distinct UI that is different from other installed apps. However, the “admin” app is not used for database administration.

For database administration, each application (that is based on the scaffolding app) includes “appadmin” (which is a single appadmin.py controller and appadmin.html view template). By default, the appadmin.html template extends the app’s layout.html template, so it retains the same look as the rest of the app. However, “appadmin” has a lot of power, so it is only intended for admins who should have complete control over the system (it is also not the most user-friendly interface).

Recently, web2py has added new functionality to enable more user-friendly database administration with varying levels of permissions for different users. Here’s an example:

auth.settings.manager_actions = dict(
    all=dict(role='Super', heading='Manage Database', tables=db.tables),
    content=dict(role='Content Manager',
                 tables=[db.articles, db.recipes, db.comments])

The above specifies two roles, “Super” and “Content Manager”. “Super” users can manage all tables in the db database, and “Content Manager” users can manage only the “articles”, “recipes”, and “comments” tables. The above exposes the following two URLs for managing the respective sets of database tables:

URL('appadmin', 'manage', args=['all'])
URL('appadmin', 'manage', args=['content'])

Each page includes a tab for each table, using SQLFORM.grid to display and edit the data. The view extends the app’s layout.html, so it looks just like the rest of the application.

Of course, if this isn’t flexible enough for you, you could easily create custom pages that use SQLFORM.grid or SQLFORM.smartgrid for managing the database. Another option is to use the Crud system — the scaffolding application includes a data() function that enables database management using Crud.

If you need any help, ask on the Google Group.

👤Anthony

Leave a comment