auth_group django_admin_log auth_group_permissions django_content_type auth_message django_session auth_permission django_site auth_user httpconfig_configdirective auth_user_groups httpconfig_vhostdirective auth_user_user_permissions httpconfig_virtualhost sqlite> drop table httpconfig_configdirective; sqlite> drop table httpconfig_vhostdirective; sqlite> drop table httpconfig_virtualhost; sqlite> .exit $ ./manage.py syncdb
Creating table httpconfig_configdirective
Creating table httpconfig_virtualhost
Creating table httpconfig_vhostdirective
Installing index for httpconfig.VHostDirective model
Installing json fixture 'initial_data' from absolute path.
Installed 62 object(s) from 1 fixture(s)
You're nearly ready to start managing the object in the administration application; just register all the model classes with the administration interface and restart the Apache web server. As you already know, you have to create the admin. py file in the application directory with contents similar to Listing 5-5.
Listing 5-5. Basic administration hooks from django.contrib import admin from www_example_com.httpconfig.models import *
class VirtualHostAdmin(admin.ModelAdmin): pass class VHostDirectiveAdmin(admin.ModelAdmin): pass class ConfigDirectiveAdmin(admin.ModelAdmin): pass admin.site.register(VirtualHost, VirtualHostAdmin) admin.site.register(ConfigDirective, ConfigDirectiveAdmin) admin.site.register(VHostDirective, VHostDirectiveAdmin)
If you navigate to the administration console, which you can find at http: //www.example. com/admin/, you will be provided with the login screen. You can log in with the user account that you created during the first syncdb call. Once logged in, you'll be presented with the standard administration interface, which lists all model classes and allows you to create the individual entries. Now, you must appreciate how much work this has already spared you from—you don't need to deal with user management, model object discovery, or any other housekeeping tasks. However, the admin interface is generic and has absolutely no knowledge about the purpose behind your data models and what fields are important to you.
Let's take our model as an example. The main entity for you is the Virtual Host. However, if you navigate to it in the administration interface, you'll only see one column in the listing view. If you have added any entries you'll see that it's the description field that is displayed. Click the Add button to add a new Virtual Host. All property fields are displayed, but what about the configuration directives? These need to be created separately on a different screen, and then you have to link each directive to the appropriate Virtual Host. That's not very useful, is it?
Luckily, the Django administration module is very flexible and can be customized to accommodate most of the requirements that you can think of. We'll improve the look and feel of the administration interface and add more functionality to it in the next sections.
Was this article helpful?