Model and Admin

Preparation

  • VNC

Description

Build a simple application to show how easy it is to create models and provide an admin interface for the model.

  • Partner:

    • id, default (provided by Django).

    • name, e.g. Sainsbury.

  • Promotion:

    • id, default (provided by Django).

    • partner_id, Partner ID (see above table).

    • promo_code, Promotion code e.g. SAINS01.

    • start_datetime, Start date of the promotion.

    • thanks_message, Displayed on the web site page.

    • terms, Terms and Conditions.

Steps

Introduction

  • Django - written in python:

  • Use Case:

    • To build simple a simple admin interface when we need to collect some data e.g. Trips, Promo Codes, where we typically receive the data in an Excel spreadsheet or Word document and have to spend significant time moving and formatting the data manually.

Preparation

  • Created project and application.

    A couple of command line tools to create a basic project and application:

    • Project: demo_model_and_admin.

    • Application: promotion.

  • Database settings - using SQLite - (for development).

    cd demo_model_and_admin\
    python manage.py syncdb
    
  • Set-up basic admin interface.

Model

  • A simple class with a method creating a string representation of the object.

  • Create the database table:

    python manage.py syncdb
    
  • Enable in the admin interface.

  • Another model which uses the first model as a lookup.

  • Admin interface options.