Writing an app – most important features
To create a web application that stores e-mail addresses, we will need a table that stores the data and web pages that allow the end user to add, delete, and review the address book. Furthermore, we may want to transform the address book to read as a spreadsheet, or send the data to another app through the Internet. There are specific Django features to accomplish all these actions (models
, views
, admin
, API REST-framework, and commands
) and we will now discuss the way the data is stored.
Models
To create an e-mail address book, we need to store, in a table, the name of each contact with their e-mail address. A table in Django is called a model and it is defined in the models.py
file:
from django.db import models from django.utils.translation import ugettext_lazy as _ class Person(models.Model): name = models.CharField(_('Name'), max_length=255, unique=True) mail = models.EmailField(max_length=255, blank=True) #display name on admin panel...