Getting ready

To demonstrate the capabilities of the Django core form rendering API, let's create a bulletin_board app and put it in INSTALLED_APPS in the settings. If you're using Docker, as described in the Creating a Docker project structure recipe in Chapter 1, Getting Started with Django 2.1, you will also need to add the new app to docker-compose.yml.

We will have a Bulletin model there with fields for bulletin_type, title, description, contact_person, phone, email, and image, as follows:

# bulletin_board/models.py
from django.db import models
from django.utils.translation import ugettextlazy as

from utils import CreationModificationDateMixin


TYPE_CHOICES = (
('searching', _("Searching")),
('offering', _("Offering")),
)


class Bulletin(CreationModificationDateMixin, models.Model):
class Meta:
verbose_name = _("Bulletin")
verbose_name_plural = _("Bulletins")
ordering = ("-created", "title",)

bulletin_type = models.CharField(_("Type"),
max_length=20,
choices=TYPE_CHOICES)
title = models.CharField(_("Title"),
max_length=255)
description = models.TextField(_("Description"),
max_length=300)
contact_person = models.CharField(_("Contact person"),
max_length=255)
phone = models.CharField(_("Phone"),
max_length=50,
blank=True)
email = models.EmailField(_("Email"),
max_length=254,
blank=True)
image = models.ImageField(_("Image"),
max_length=255,
upload_to="bulletin_board/",
blank=True)

def __str__(self):
return self.title

Remember to make an initial migration for the new model and run that against your database.

If you haven't done so yet, create a base.html template according to the example in the Arranging the base.html template recipe in Chapter 4Templates and JavaScript. Make sure to include the Bootstrap 4 frontend framework CSS and JavaScript in the templates. To this, we'll also want to add the CSS for the Ion Icons icon set, within the base_stylesheet block, as follows:

{# templates/base.html #}
{% load static %}

{% block base_stylesheet %}
<link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
{# ... #}
{% endblock %}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.237.255