RapidSMS Developers Guide/Customizing Admin U.I

From Wikibooks, open books for an open world
< RapidSMS Developers Guide
Jump to: navigation, search

Admin User Interface is a Django feature. It creates automaticaly an Admin U.I from your models which allows registered users to

  • Add record for Models
  • Edit records for Models
  • Delete records for Models

Enabling Django admin in RapidSMS[edit]

As RapidSMS doesn't gives access to the Django settings.py file, we need to manually enable the Django admin (whether we want admin support for our own Models or not).

The easiest way is to include the admin app from the RapidSMS repository. See Installation.

You will then have access to Django admin at /admin/ URL on your web server. Use the credentials you used during the first syncdb to log-in.

Add Django Admin Support[edit]

Inside your App, create a file named admin.py.

admin.py must include the following minimum statements to work:

#!/usr/bin/env python
# encoding=utf-8

from django.contrib import admin
from myapp import models

admin.site.register(MyModel)

In this example, we are enabling Django admin for the model MyModel of our myapp App.

You can now edit your Model's data from the Admin U.I.

Improving Model Admin U.I[edit]

One Django feature that most RapidSMS apps are using is Customized Admin for Models.

It allows features like content filtering, enhanced display or search.

Example:

#!/usr/bin/env python
# encoding=utf-8

from django.contrib import admin
from models import Person, Activity

class PersonAdmin(admin.ModelAdmin):

    list_display = ('name', 'age', 'sex_name', 'activity', 'entered_on')
    list_filter = ('activity', 'sex')
    ordering = [('-entered_on')]
    search_fields = ['first_name', 'last_name', 'activity__name']

admin.site.register(Person, PersonAdmin)

This example registers a custom Admin Model for the Person Model.

  • List of records will display the properties from the list_display tuple.
  • List of records can be filtered by activity or sex.
  • List of records will be ordered by entered_on (DESC) by default
  • List of records will present a search box which can search on fields given.

External Links[edit]

Coding standards and documentation · Web Views & Templates