Demo Application
See a functional demo application for a ticket management system using Eventbrite APIs.
We'll cover the following...
In this lesson, we will see a sample Django application of a ticket management system. There are two categories of users: organizer and user. We have used the following endpoints in the application:
- View events.
- Create an event.
- Create a ticket.
- Publish an event.
- Buy tickets using the checkout widget of Eventbrite.
Workflow and APIs
Let’s dive into the code and see how we’ve integrated different Eventbrite APIs into our web application.
User function
Let’s discuss the function of the user in the views.py file:
- Lines 14–22: The index function retrieves live events using the organization ID and returns the events to the user’s GUI.
Click the link below the “Run” button to open the user’s page.
Organizer functions
Let’s discuss the functions of the organizer in the views.py file:
- Lines 24–31: The
dashboardfunction retrieves all events using the organization ID and returns the events to the organizer’s GUI. - Lines 33–71: The
create_eventfunction receives necessary inputs from the GUI and creates the event. - Lines 73–105: The
create_ticketfunction receives necessary inputs from the GUI to create a ticket for the event. We have to create at least one ticket to publish an event. - Lines 107–123: The
publish_eventfunction shows the events with draft status. When we click the “Publish Event,” theevent_idis used to change its status to publish as the user can only see the published events.
To open the organizer’s page, use the link given below:
{{EDUCATIVE_LIVE_VM_URL}}/organizer
Demo
Click the “Run” button to run the demo application in the widget below. Before that, don’t forget to enter the PRIVATE_TOKEN and ORGANIZATION_ID to start the server.
Note: The following widget only shows the necessary files required to explain the endpoints of Eventbrite API.
"""
Django settings for demo project.
Generated by 'django-admin startproject' using Django 3.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-h^#u(di)#-il-!joa*_lkb8pc%l2!seueooz!$w0)1)$716g@@'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['{{EDUCATIVE_LIVE_VM_URL}}'.replace('https://','')]
CSRF_TRUSTED_ORIGINS = ['{{EDUCATIVE_LIVE_VM_URL}}']
SESSION_COOKIE_SAMESITE = 'strict'
CSRF_COOKIE_SAMESITE = 'strict'
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ebapi'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'demo.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'demo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
FILE_UPLOAD_PERMISSIONS = 0O640
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'